필터 지우기
필터 지우기

How to catch an error

조회 수: 2 (최근 30일)
John Miller
John Miller 2012년 6월 4일
Hi,
if I get an error I want change the algorithm: like this:
if ERROR
ALGORITHM 2
else
ALGORITHM 1
end
Hope someone can help.
Thank YOu!

채택된 답변

Image Analyst
Image Analyst 2012년 6월 4일
Try it like this:
try
% No error yet, so try to run algorithm 1
algorithm1();
catch ME
% You get here if algorithm 1 bombs.
% Create an informative error message.
errorMessage = sprintf('An error occurred in function blah_fubar(). The error reported by MATLAB is:\n\n%s\nClick OK to run algorithm2()', ME.message);
% Print error message to command window.
fprintf('%s', errorMessage);
% Alert the user via a popup message.
uiwait(warndlg((errorMessage));
% Now run algorithm 2, because we had the error occur.
algorithm2();
end
  댓글 수: 1
John Miller
John Miller 2012년 6월 4일
Waoow nice ! :) This is perfect
THANK YOU VERY MUCH FOR YOUR HELP!!

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

추가 답변 (1개)

the cyclist
the cyclist 2012년 6월 4일
You need the try-catch construct. Look up
>> doc try

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by