Creating output m-file in matlab

Tags: matlab

Suppose 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?


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
By : b3.

In Matlab a semicolon ";" at the end of a line suppresses output. So,

>> d=1+2;
>> d=1+2
d = 

Or you can use disp as in the first answer.

>> disp(num2str(d));

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?

By : Azim

By : Scottie T

This video can help you solving your question :)
By: admin