B Seven
B Seven

Reputation: 45951

How to load a .mat file and set the variable name in Octave or Matlab?

Apparently Matlab load loads the data from a .mat file into the variable that it was saved.

How can you load a single matrix from a .mat or binary file into an arbitrary variable?

Upvotes: 3

Views: 6891

Answers (1)

Andrew Janke
Andrew Janke

Reputation: 23908

Load it in to a struct and pop it out to your variable.

saved_name = 'varname_it_was_saved_as';
s = load('some_file.mat', saved_name);
my_new_variable = s.(saved_name);

I always use the struct forms of save and load for production code. It's cleaner because it doesn't dynamically fiddle with your workspace.

See help load for details.

Upvotes: 9

Related Questions