Load all data files in a directory in Octave

directory, matrix, octave

Solution

I'm not 100% sure of your question. When you mention getting matrices from cells I'm guessing your problem is extracting the filename from the output of `readir` and `glob`. If that's so, you can get the names with `filenames(1)` (if you use `{}` to index a cell array you get another cell array).

filelist = readdir (pwd)
for ii = 1:numel(filelist)
  ## skip special files . and ..
  if (regexp (filelist{ii}, "^\\.\\.?$"))
    continue;
  endif
  ## load your file
  load filelist{ii}
  ## do your maths
endfor

You can use a struct on the `load` line if the filenames are good `data.(filelist{ii}) = load filelist{ii}`.

Problem

I need to load all data in a directory into octave (no matter what their filenames are), so that the data from separate files are loaded into separate matrices. How can I do that? I've tried to use `dir` and `glob` and then use a `for` loop but I don't know how to get matrices from cells.

Original source