フィルターのクリア

How to solve override writing file problem?

1 回表示 (過去 30 日間)
Jason
Jason 2016 年 3 月 23 日
コメント済み: Star Strider 2016 年 3 月 23 日
I have try-catch in my code, when I catch the error, I write the error information to a file, but it always override the previous error information, how to do to avoid this problem? I want to append the next error information to the previous error information.
for p=3:10
...
Day = fdname(p).name;
try
...
catch
fid = fopen('output-2016.err', 'wt');
fprintf(fid, 'Inconsistent data in %s, skipped.\n', p);
fprintf(fid, 'Inconsistent data in %s, skipped.\n', Day);
fclose(fid);
end

採用された回答

Star Strider
Star Strider 2016 年 3 月 23 日
編集済み: Star Strider 2016 年 3 月 23 日
I would put the fopen and fclose calls outside the loop:
fid = fopen('output-2016.err', 'wt');
for p=3:10
...
Day = fdname(p).name;
try
...
catch
fprintf(fid, 'Inconsistent data in %s, skipped.\n', p);
fprintf(fid, 'Inconsistent data in %s, skipped.\n', Day);
end
. . . CODE . . .
end
fclose(fid);
  2 件のコメント
Jason
Jason 2016 年 3 月 23 日
awesome. thanks
Star Strider
Star Strider 2016 年 3 月 23 日
My pleasure!

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

その他の回答 (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