How do I continue to read files in a loop when an error occurs?

조회 수: 7 (최근 30일)
Aru E
Aru E 2020년 11월 29일
댓글: Walter Roberson 2020년 11월 30일
Hello, I am trying to read .FIT files provided by my teacher and when reading the last bunch of them an error occurs. I tried using a try catch to continue, and it skips over and continues the loop, but I am not getting my value D.
Error using fitsinfo>openFile (line 760)
Unable to open file. File might be corrupt or filename might have unsupported characters.
for l = 100:999
try
fit2file = sprintf('x.000000%d.FIT',l);
D = fitsread(fit2file);
catch
end
end
Thank you in advance
  댓글 수: 2
Mario Malic
Mario Malic 2020년 11월 29일
Try reading the file that causes the error to check if it's corrupted. If It's not, consider renaming your files, 'x.00001.FIT' could be prone to failures.
Walter Roberson
Walter Roberson 2020년 11월 30일
your loop overwrites D with the last file content it was able to read, but does not define D if no files could be read.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by