Borrar filtros
Borrar filtros

Writing to a text file

1 visualización (últimos 30 días)
Sina Shojaei
Sina Shojaei el 2 de Mzo. de 2015
Respondida: Star Strider el 2 de Mzo. de 2015
Hi All, I want to save a matrix in a text file. fprintf and fwrite both create the .txt file in ASCII format which is not what I want. This is what I've got:
Cyle=[1 2 3];
fid=fopen('Output.txt','w');
fprintf(fid,char(Cyle),'char'); %// or fwrite(fid,char(Cyle),'char');
fclose(fid);
Is there a way around it?
Also, can I add a comment on the first line of the text file?
Thanks Sina

Respuestas (1)

Star Strider
Star Strider el 2 de Mzo. de 2015
If you don’t want to save it as an ASCII file, use the save function to save it as a binary file. You can also save the comment.
Example:
Cyle=[1 2 3];
Comment = 'I really like the way MATLAB solved this problem!';
save('MyData.mat', 'Comment', 'Cyle')
or alternatively:
save MyData.mat Comment Cyle

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by