Search code examples
ioloadoctave

How to use the load function in Octave not knowing the variable name of the saved data?


I have several 100 *.mat files with matrices with same shapes. But over time this matrices were saved with different names. Lets say for this example a or b.

How can I now load and process this data without knowing the name using a new name instead?

An if condition is not an option, because there are too many different names.

I already tryed:

data = load('example_file.mat')

but then I need again the old variable names to access the matrices with data.a or data.b ...

What I need is something like:

load('example_file.mat') as matrix

Is this possible in Octave?


Solution

  • Your attempt

    data = load('example_file.mat')
    

    is the right start. You can examine data to find out what variables it contains. Assuming there’s always a single matrix in the MAT-file,

    names = fieldnames(data);
    data = data.(names{1});