Write to txt, delimited by char(10)

8 visualizaciones (últimos 30 días)
Ivan Gonzalez Bustos
Ivan Gonzalez Bustos el 11 de Dic. de 2018
Editada: Walter Roberson el 31 de Jul. de 2022
Let
x = ['a' char(10) 'b'];
How can I print this to a text file say, test.txt, in such a way that it reads a in the first line and b in the second one?

Respuesta aceptada

GT
GT el 11 de Dic. de 2018
x = ['a' char(10) 'b'];
fp = fopen('test.txt','w');
fwrite(fp,x);
fclose(fp);
I am on a Mac and using R2018b. That being said the above should work on all OS and most MATLAB releases.
There is also a command in MATLAB called newline (which is the same as char(10)
  4 comentarios
GT
GT el 11 de Dic. de 2018
This has to do with your OS, and editor and how it interprets new lines.
char(10)
char(13)
Sometimes you would need both a \r\n for editors to recognize newline.
Ivan Gonzalez Bustos
Ivan Gonzalez Bustos el 12 de Dic. de 2018
Editada: Walter Roberson el 31 de Jul. de 2022
Yep, it was Microsoft notepad

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by