Search code examples
matlabmemorymatlab-load

Matlab: Loading files


If I use the load function by matlab I normally end up doing something like this:

temp = load('filename.mat');
realData = temp.VarName;
clear temp

or

realData = load('filename.mat');
realData = realData.VarName;

is any of this methods superiour to the other, especially in terms of memory usage? Or is there a more direct approach to avoid this temporary struct?

Thx Thomas


Solution

  • Well, if you just do load('filename.mat');, all the variables end up in the current scope.

    I doubt there's any meaningful memory cost to either of your methods, though. Matlab uses copy-on-write.