MATLAB: Save variables in .mat files with desired name.

assigninmatsave

I have a function where I do my calculation to get A cell or array. Now I want to save this array in a .mat file but I want to change the variable name.
myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation

save Data.mat myData
This saves my data in Data.mat file but with variable name myData. Now I want to save values of myData in .mat file but I want to save the value under a variable name given via input function. Something like:
myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation
newName = input('I want to save the variable under the name:', 's');
save Data.mat ???
I hope that make sense
Thanks

Best Answer

myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation
newName = input('I want to save the variable under the name:', 's');
S.(newName) = myData;
save('Data.mat', '-struct', 'S') % EDITED