Illustration of Writing variables to a file:
For illustration, in the below session in the Command Window, 3 variables are generated; these are then exhibited using who. Then, the variables are saved to file named 'sess1.mat'. The who function is then used to show the variables stored in that file.
>> mymat = rand(3,5)
mymat =
0.9501 0.4860 0.4565 0.4447 0.9218
0.2311 0.8913 0.0185 0.6154 0.7382
0.6068 0.7621 0.8214 0.7919 0.1763
>> x = 1:6;
>> y = x.^2;
>> who
Your variables are:
mymat x y
>> save sess1
>> who -file sess1
Your variables are:
mymat x y
To save only one variable to a file, the format is as shown below:
save filename variablename
For illustration, only the matrix variable mymat is saved in a file known as sess2
>> save sess2 mymat
>> who -file sess2
Your variables are:
mymat