Writing data to a file

1 回表示 (過去 30 日間)
Millie Jones
Millie Jones 2020 年 3 月 26 日
コメント済み: Millie Jones 2020 年 3 月 28 日
I'd like write 1 to 20 to a file, but not sure how I would go about finishing the code. I've attempted to use a for loop here and think this is the right approach as it does count from 1 to 20, but the end of my code looks like this...
And I'd like to remove the two ans, but have tried to put semi colons in different places to hide the ans and doesn't seem to work. Here is my (attempted) code:
fileid= fopen('data.dat','w')
for a = 1.0:1:20;
disp(a)
end
fprintf(fileid,'%s',a)
fclose(fileid)

採用された回答

Bhaskar R
Bhaskar R 2020 年 3 月 26 日
fileid= fopen('data.dat','w');
fprintf(fileid, '%d\n', [1:20]');
fclose(fileid)
  1 件のコメント
Millie Jones
Millie Jones 2020 年 3 月 28 日
Thank you :-) That makes a lot more sense, I realised I wasn't actually writing anything to my file

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by