fprintf and line break
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
I'm trying to write an array into a text file using fprintf. It's working fine on my Mac Matlab Version 2015b. However, on my work PC with a 2011 version, it is not breaking the line, but writing everything into one single line. Since I only have those two setups, it's hard for me to figure out if it is a Mac/PC or a version issue. Also, maybe I'm missing something in the syntax?
filetimenormal=fullfile(savepath,'file.txt');
ftnormal=fopen(filetimenormal, 'w');
header={'year','mm', 'dd', 'hh', 'min', 'sec', 'file', 'type'};
fprintf(ftnormal,'%s \t %s \t %s \t %s \t %s \t %s \t %s \t %s \n',header{1,:});
[nrows,ncols] = size(newtimearray);
for row = 1:nrows
fprintf(ftnormal,'%s \t %s \t %s \t %s \t %s \t %s \t %s \t %s \n' ,newtimearray{row,:});
end
Thank you!
댓글 수: 3
답변 (2개)
Walter Roberson
2016년 8월 30일
For MS Windows, use
ftnormal=fopen(filetimenormal, 'wt');
instead of
ftnormal=fopen(filetimenormal, 'w');
댓글 수: 0
Image Analyst
2016년 8월 30일
Depending on the program (notepad, wordpad, MSWord, etc.) the new lines are interpreted differently. If \n is not working, try \n\r or \r\n. One of those should work.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!