MATLAB: How to use the functional form of the LOAD and SAVE commands

argumentdualityMATLAB

I would like to use the functional form of the LOAD and SAVE commands.

Best Answer

The documentation and help entries for the SAVE function:
This describes the basic syntax for this command. You can also type the following at the MATLAB command prompt:
help save
for extensive syntax explanation.
Here is an additional example:
var1 = [10 20 30];
var2 = 'var2';
save('fname','var1','var2')
var3 = 100;
save('fname','var3','-append')
The syntax is the same for the LOAD command. For example, the following code will SAVE each column of a variable 'a' to different ascii files:
a = rand(6); %make a
filename = ['a1.txt';'a2.txt';'a3.txt';'a4.txt';'a5.txt';'a6.txt';]; %list your file names
for i = 1:length(a)
temp = a(:,i);
save(filename(i,:),'temp','-ascii'); %save to the specified file
end