tags:

views:

1577

answers:

3

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?

+1  A: 
disp(num2str(d));
Scottie T
+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
+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