Write to txt, delimited by char(10)

조회 수: 2 (최근 30일)
Ivan Gonzalez Bustos
Ivan Gonzalez Bustos 2018년 12월 11일
편집: Walter Roberson 2022년 7월 31일
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?

채택된 답변

Gareth
Gareth 2018년 12월 11일
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
Gareth
Gareth 2018년 12월 11일
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 2018년 12월 12일
편집: Walter Roberson 2022년 7월 31일
Yep, it was Microsoft notepad

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by