Export data to .txt file using writematrix function
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Tanisha Gosain
el 19 de Jun. de 2020
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 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!