Sahlabadum 35
Sahlabadum 35

Reputation:

Creating output m-file in 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?

Upvotes: 1

Views: 10764

Answers (3)

b3.
b3.

Reputation: 7155

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

Upvotes: 2

Azim J
Azim J

Reputation: 8290

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?

Upvotes: 9

Scottie T
Scottie T

Reputation: 12175

disp(num2str(d));

Upvotes: 1

Related Questions