フィルターのクリア

Export data to .txt file using writematrix function

3 ビュー (過去 30 日間)
Adam Bosco
Adam Bosco 2020 年 4 月 16 日
回答済み: Tanisha Gosain 2020 年 6 月 19 日
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?

回答 (1 件)

Tanisha Gosain
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);
You can read more about fprintf and how to use it here.

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by