Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: loading a .mat file, why is it a struct? can I just have the stored vars loaded into memory?

Relevant code:

function result = loadStructFromFile(fileName, environmentName) 
    result = load(fileName, environmentName);


bigMatrix = loadStructFromFile('values.mat','bigMatrix'); 

But when I look in the workspace, it shows 'bigMatrix' as a 1x1 struct. When I click on the struct, however, it is the actual data (in this case a a 998x294 matrix).

like image 878
NullVoxPopuli Avatar asked Jan 17 '11 22:01

NullVoxPopuli


1 Answers

As the documentation of LOAD indicates, if you call it with an output argument, the result is returned in a struct. If you do not call it with an output argument, the variables are created in the local workspace with the name as which they were saved.

For your function loadStructFromFile, if the saved variable name can have different names (I assume environmentName), you can return the variable by writing

function result = loadStructFromFile(fileName, environmentName) 
    tmp = load(fileName, environmentName);
    result = tmp.(environmentName); 
like image 64
Jonas Avatar answered Oct 08 '22 22:10

Jonas