Write data .txt format with different vector in different column
Ältere Kommentare anzeigen
I have two different single column matrix
A = [1 2 3 4 5 6 7]; B = [110 120 114 116 117 119 121];
I want to write it in the .txt format as shown below,
1 110
2 120
3 114
4 116
5 117
6 119
7 121
Now I am try to do it with the below mentioned code but I am getting all the data in a single column,
fid=fopen('MyFile.txt','wt');
fprintf(fid,'%d\r\n',A);
fprintf(fid,'%d\r\n',B);
fclose(fid);
Akzeptierte Antwort
Weitere Antworten (1)
Guillaume
am 3 Jul. 2018
A loop is a waste of time:
fid = fopen('MyFile.txt', 'wt');
fprintf(fid, '%d %d\n', [A; B]);
fclose(fid);
This assumes that A and B are row vectors as you've shown but not as you've stated. A and B must of course have the same number of elements.
I assumeed you wanted a space between each column.
2 Kommentare
Stephen23
am 3 Jul. 2018
+1 no loop is the way to go.
Kategorien
Mehr zu Language Support finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!