필터 지우기
필터 지우기

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 CenterFile Exchange에서 Low-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