Export data to .txt file using writematrix function
3 ビュー (過去 30 日間)
古いコメントを表示
I am using the writematrix(A,'myData.txt','Delimiter','tab') function to export data to a txt file. I need the delimiter but i also need the txt to start at row 5 to avoid the header. I know that for xls you can add 'Range','A5' to specify where the data starts but how do you do that with a txt file?
0 件のコメント
回答 (1 件)
Tanisha Gosain
2020 年 6 月 19 日
Hi, the 'Range' parameter in writematrix only works for excel files. You can read more about how to specify range while writing to an excel file here.
You can do the following to export data to .txt file:
A = magic(8);
numRows = 4;
%skipping first 4 rows
fid = fopen('myData.txt','w');
for i = 1:numRows
fprintf(fid, '%s\n','');
end
%making format specifications
[r,c] = size(A);
s2 = '';
s1 = '%d\t';
for i = 1:c
s2 = strcat(s2,s1);
end
%writing A to myData.txt
for iter = 1:r
s = strcat(s2,'\n');
fprintf(fid,s,A(iter,:));
end
fclose(fid);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!