MATLAB: Save correct variable name in workspace

MATLABsavevariables

I have a function in matlab.
function [MEAN STD]=result(data)
MEAN=[mean(data)];
STD=std(data);
Training_data=[MEAN STD]
savefilename=sprintf('%s',inputname(1))
save(savefilename,'Training_data')
end
i set data's filename=ET1_A_l1(imported to workspace alrdy)(ET1_A_l1=[1;2;1;3;1;4] to find the mean and std of selected data(ET1_A_l1),and save the statistical feature into .mat form as shown in below:
>>[MEAN STD]=result(ET1_A_l1)
As a result, the name of save file is ET1_A_l1.mat,and I import ET1_A_l1.mat into the workspace,it shows the 'Training_data' as the variable name.
Is there any good idea to change the variable name(Training_data) to ET1_A_l1 in workspace??

Best Answer

savefilename = inputname(1); % No need for sprintf
save(savefilename, 'Data');
...
Data = load(FileName);
Now it is much safer and clearer to use Data.ET1_A_l1 instead of assigning ET1_Al1 directly. Imagine you use the name of a built-in function, e.g. "sin". Then loading this as variable directly will lead to a lot of troubles.