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.

 Réponse acceptée

Thorsten
Thorsten le 21 Jan 2016
Modifié(e) : Thorsten le 21 Jan 2016
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)

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by