Writing to a text file

3 Ansichten (letzte 30 Tage)
Sina Shojaei
Sina Shojaei am 2 Mär. 2015
Beantwortet: Star Strider am 2 Mär. 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

Antworten (1)

Star Strider
Star Strider am 2 Mär. 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

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by