Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print an array to a .txt file in Matlab?

I am just beginning to learn Matlab, so this question might be very basic:

I have a variable

a=[2.3 3.422 -6.121 9 4.55]

I want the values to be output to a .txt file like this:

2.3
3.422
-6.121
9
4.55

How can I do this?

fid = fopen('c:\\coeffs.txt','w'); //this opens the file
//now how to print 'a' to the file??
like image 434
Lazer Avatar asked Sep 21 '09 21:09

Lazer


1 Answers

The following should do the trick:

fid = fopen('c:\\coeffs.txt','wt');  % Note the 'wt' for writing in text mode
fprintf(fid,'%f\n',a);  % The format string is applied to each element of a
fclose(fid);

For more info, check out the documentation for FOPEN and FPRINTF.

like image 82
gnovice Avatar answered Oct 03 '22 03:10

gnovice