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??
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With