Trying to pass/ignore an Error in a loop.

I have a loop that check the best parametrers in many timeseries, but there are some of them where Matlab cannot check, so the loop is stopping. In those cases i just want the loop to continue, ignoring the error. I am thinking "for i=1:1000 ... if find an error go to i+1 " but there is something like this??
Thanks!

 채택된 답변

Wayne King
Wayne King 2013년 4월 7일
편집: Wayne King 2013년 4월 7일

0 개 추천

Without more detail, I don't know if this will work in your scenario, but one possibility is a try block
x = randn(3,2);
y = randn(3,2);
try
z = x*y;
catch ME
z = x.*y;
end
If an error occurs in the catch end block, then the execution will stop unless you catch that error with a try -- catch

댓글 수: 4

Indeed, extra example below. The second run normally would stop the script when trying to access y(-2). Now it continues.
x = [1,-2,3];
y = [4,5,6];
for p = 1:3
try
disp(y(x(p)));
catch error
end
end
nicolas
nicolas 2013년 4월 7일
I have read this, in help documenattion. The clue is if matlab finds an error in try block to continue in catch block. Right?
nicolas
nicolas 2013년 4월 7일
ok ok, i understand. I ll try this later, because now its still running, until it finds an error again! Thanks for your time!
nicolas
nicolas 2013년 4월 7일
its working! for k=1:100 try .... catch error end end
%%and the loop continues ignoring the error thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2013년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by