MATLAB: Best way to rename a loaded variable

loadnamespacevariable names

Say that I have a .mat file that contains a variable, and I need to load this variable and give it a different name. Is there any other (/better) way to do this than:
load(myFile, myVar)
eval(['myNewname = ' myVar '; clear ' myVar])
?

Best Answer

Say you have the name of your variable:
VAR = 'S';
Now you want to load that variable, but with the name T. This method follows the general rule of thumb to avoid 'poofing' variables into the workspace.
T = load('myfile',VAR); % Function output form of LOAD
T = T.(VAR)