Printing to text file
Mostrar comentarios más antiguos
Pretty simple. I want to print this to a text file:
4
1
2
3
4
but instead I am getting this:
41234
Here's my code:
z = 4;
fid = fopen([mnl_data_path, 'packages.txt'], 'w');
a = num2str(z);
fprintf(fid,'%s\n',a);
for j = 1:1:z
a = num2str(j);
fprintf(fid,'%s\n',a);
end
fclose(fid);
Why isn't it printing to a new line?
Respuestas (4)
the cyclist
el 25 de Ag. de 2012
0 votos
Strange. I get each digit on a separate line, as you intend.
I am using the prerelease of R2012b, on a Mac running OSX 10.6.8.
Edward Umpfenbach
el 26 de Ag. de 2012
0 votos
Edward Umpfenbach
el 26 de Ag. de 2012
0 votos
2 comentarios
per isakson
el 26 de Ag. de 2012
Did you try View | Show Symbol | Show All Characters in notepad++?
Image Analyst
el 27 de Ag. de 2012
Try wordpad. I think wordpad and notepad behave differently with regards to how they interpret \n and \r\n. You can know for sure what's there if you have access to an editor that can view in hex format.
Walter Roberson
el 27 de Ag. de 2012
0 votos
Open the file with 'wt' instead of 'w'
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!