Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How do I use the functional form of the LOAD and SAVE commands?


Date Last Modified: Wednesday, November 18, 2009
Solution ID:   1-16FP4
Product:   MATLAB
Reported in Release:   R9
Fixed in Release:   R12
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I use the functional form of the LOAD and SAVE commands?

Problem Description:

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

Solution:

The documentation and help entries for the SAVE function:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/save.shtml

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

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page