MATLAB: Save

save

I have two variables:Var1=[1 2 3] and s='myData'. I am using assignin('base',s,Var1) to assign the contents of the text file as Var1 name. now I have another variable, myData=[1 2 3]. I wonder how I can save Var1 with the new name. Please let me know if I didn't ask it clearly.
Var1=[1 2 3]
s='myData'
assignin('base',s,Var1)
%now I have another variable, myData=[1 2 3] %now I want to save it with the new name with using the contents of s variable.
Save('C:\myData',assignin('base',s,Var1))

Best Answer

save(['C:\' s],s) %save the mat file with the same name as the variable