Hallo, If i have an M-file that calculates for example d=a+b+c(The values on a,b,c were given earlier).What command should I use in order to produce an output M-file showing the result of this sum?
+6
A:
In Matlab a semicolon ";" at the end of a line suppresses output. So,
>> d=1+2;
>> d=1+2
d =
3
Or you can use disp as in the first answer.
>> disp(num2str(d));
3
If you want to write the values of a variable to a file you can use either dlmwrite (use Matlab's help function to get more info) or save commands. For dlmwrite, the usage is basically
>> dlmwrite('filename',d,',')
which writes the vector (matrix), d, to the text file named filename using a comma as the delimiter between elements.
The other option is to use the save command, as in
>> save('filename','d')
which will save the variable 'd' to a MAT file (see help save for more information). Hope this helps?
Azim
2008-10-10 20:01:50
+1
A:
To expand on Azim's answer, the save command can be used to save variables to a text file. In your case you would use:
save 'filename' d -ascii
b3
2008-10-11 06:46:06