Save text files without an empty line in the end?

For some reason I need to save a matrix to a .txt file without an extra blank line in the end. For example, when I save [1;2;3] to a text file, the file will have an empty forth row, which I want to get rid of. I've tried 'save', 'dlmwrite', 'fprintf',...but none of them worked.

 채택된 답변

Thorsten
Thorsten 2016년 1월 21일
편집: Thorsten 2016년 1월 21일

0 개 추천

Use fprintf with newline \n for all but the last entry in x, which is written separately without \n:
x = [1;2;3];
fid = fopen('foo.txt', 'w');
fprintf(fid, '%f\n', x(1:end-1))
fprintf(fid, '%f', x(end))
fclose(fid)

추가 답변 (0개)

카테고리

질문:

2016년 1월 21일

댓글:

2016년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by