简体   繁体   中英

How to export data from matlab into a text file

I have multiple arrays of data, out of which only x,y and z arrays are required to be exported as text. I know how to export a single array, but am unable to export the 3 columns of data as text file. please help, I tried with the following..

        fid = fopen('g.txt','w');
        fprintf(fid,'%f \n',x,y,z);
        fclose(fid);

try dlmwrite , for example:

x=[1:10]';
y=2*x;
z=3*x;
dlmwrite('g.txt',[x,y,z],'delimiter', '\t');


>type 'g.txt'

1   2   3
2   4   6
3   6   9
4   8   12
5   10  15
6   12  18
7   14  21
8   16  24
9   18  27
10  20  30

You don't want delimiter write, you want csvwrite . It will open nicely in Excel and similar programs.

The following example creates a comma-separated value file from the matrix m.

m = [3 6 9 12 15; 5 10 15 20 25; ...
     7 14 21 28 35; 11 22 33 44 55];

csvwrite('csvlist.csv',m)
type csvlist.csv

3,6,9,12,15
5,10,15,20,25
7,14,21,28,35
11,22,33,44,55

See http://www.mathworks.com/help/matlab/ref/csvwrite.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM