Even if you specify only one variable name, LOAD will still output it to the structure. In your case, one option that you have is to use the STRUCT2CELL function to convert the output from LOAD to an array of cells, then return this result using the list of variable output arguments :
function varargout = loadStructFromFile(fileName,environmentName) varargout = struct2cell(load(fileName,environmentName)); end
Using VARARGOUT has the added benefit that if the environmentName matches multiple variables in the .MAT file, you can return them all from your function. For example, if your .MAT file has three variables N1 , N2 and N3 , and environmentName N* , you can get them all by calling your functions with several outputs:
[N1,N2,N3] = loadStructFromFile('values.mat','N*');
gnovice
source share