changing the name of the file that is corrupt
조회 수: 3 (최근 30일)
이전 댓글 표시
I am running a script where i load .cnt files and reaction files that are stored as a .txt files. What i didn't realize is that there was one file that was corrupt and that caused my script to not work. I took care of that without any trouble. However, this got me thinking of what would happen in the future. Since this is a lab where i work at people tinker with those files and sometimes this said tinkering could cause it to not function. Is there a way where i could specify the errors that i could get and if the script comes across those errors, the code would then mark them as corrupt and notify the user that they need to be taken out of the data run.
댓글 수: 0
채택된 답변
Image Analyst
2016년 3월 11일
Yes, just use try catch
for k = 1 : numberOfSelectedFiles
try
% read file
% if it works it does more code.
catch
% File can't be read - it's corrupt. Alert the user.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
continue; % Skip to bottom of for loop and continue with the next iteration.
end
end % of for loop
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!