フィルターのクリア

Writing to a text file

1 回表示 (過去 30 日間)
Sina Shojaei
Sina Shojaei 2015 年 3 月 2 日
回答済み: Star Strider 2015 年 3 月 2 日
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

回答 (1 件)

Star Strider
Star Strider 2015 年 3 月 2 日
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

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by