Problems writing to text files
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everybody,
I know this is a known issue, but I still have some troubles getting my thing right, even with solutions suggested. I want to export some data to a text file Basically, I have a cell array with headers ( called parts) for my table, and a matrix with values (called Output).
The way I'm doing this now is:
fid = fopen(fullfile('Darab Export','Output File 2.txt'), 'w+');
fprintf(fid,'%s\t',parts{1:end-1}); %# Write all but the last label
fprintf(fid,'%s\n',parts{end});
fclose(fid);
dlmwrite(fullfile('Darab Export','Output File 2.txt'), [Output(1:20,:)],'delimiter','\t','newline', 'pc','precision','%.6f','-append') %Output(1:20,:)
However, in my case, the results is wrong, since the text file contains all the headers, but on the first line, the values are immediately pasted afterwards. I think something is going wrong with the newline part, as this does not appear in my text file. Hope you guys understand my issue, and can help my out.
Thanks in advance!
Roy
0 comentarios
Respuestas (1)
per isakson
el 11 de Jul. de 2012
Editada: per isakson
el 11 de Jul. de 2012
I have R2012a 64bit, Windows7. I tried your code with some data.
The resulting file looks ok in Notepad++, but as you describe without line breaks after the header in Notepad.
Notepad++ shows that the header is terminated by LF, char(10), and the data lines are terminated by CRLF, char(13)char(10).
Windows uses LF and DOS used CRLF - if I remember correctly. Matlab doesn't care when reading(?).
>> double(sprintf('\n'))
ans =
10
Welcome in the club of the confused!
Ver también
Categorías
Más información sobre Environment and Settings 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!