MATLAB Answers

Christine
0

continue for-loop despite matlab error

Christine
さんによって質問されました 2012 年 4 月 19 日
I want to process a number of images for data analysis. If one of the images causes a matlab error, I want the program to display a message but to continue with the analysis of the following images. So it would need to continue with the next iteration of a for loop. Is this possible and how would I do this?
Thanks, Christine

  0 件のコメント

サインイン to comment.

2 件の回答

Daniel Shub
回答者: Daniel Shub
2012 年 4 月 19 日
 採用された回答

You could do something like
for ii = 1:n
try
% your code
catch ME
warning('Something happened');
end
end

  0 件のコメント

サインイン to comment.


Christine
回答者: Christine
2012 年 4 月 19 日

Great, thanks a lot. This works fine:
for number = 1:number_of_images
try
%image analysis program
catch ME
disp('mistake in picture number'); disp(number);
end
end

  1 件のコメント

Daniel Shub
2012 年 4 月 19 日
In this case you do not need to catch the exception object (ME). You might want to check ME to make sure it was because the there was a mistake in the picture number and not some other error.

サインイン to comment.



Translated by