Export data to .txt file using writematrix function
조회 수: 2 (최근 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!