load does not behave this way, otherwise load will behave inconsistently depending on the number of variables you requested, which will lead to extremely confusing behavior.
To illustrate this, imagine that you wrote a generic program that wanted to load all the variables from a .mat file, make some changes to them, and then save them again. You want this program to work with any file, so some files may have one variable, and some may have several variables stored in them.
If load used the behavior you specified, you will need to add all kinds of logic to check how many variables were saved in the file before loading and changing.
Here is what this program would look like with the current load behavior
function modifymyfile(filename) data = load(filename); fields = fieldnames(data); for k = 1:numel(fields) data.(fields{k}) = modify(data.(fields{k})); end save(filename, '-struct', 'data') end
If the behavior was as you see fit
function modifymyfile(filename) % Use a matfile to determine the number of variables vars = whos(matfile(filename)); % If there is only one variable if numel(vars) == 1 % Assign that variable (have to use eval) tmp = load(filename, vars(1).name); tmp = modify(tmp); % Now to save it again, you have to use eval to reassign eval([vars(1).name, '= tmp;']); % Now resave save(filename, vars(1).name); else data = load(filename); fields = fieldnames(data); for k = 1:numel(fields) data.(fields{k}) = modify(data.(fields{k})); end save(filename, '-struct', 'data'); end end
I will leave this to the reader to decide which one is more legible and reliable.
The best way to do what you are trying to do is exactly what you showed in your question. Just reassign the value after loading
data = load('myfile.mat', 'var1'); data = data.var1;
Update
Even if you want the variable not to be bound to the struct when the variable has been explicitly specified, you would still encounter inconsistent behavior that would make it more difficult if my program accepted the list of variables to change as an array of cells
variables = {'var1', 'var2'} data = load(filename, variables{:}); % Would yield a struct variables = {'var1'}; data = load(filename, variables{:}); % Would not yield a struct