How to skip an input in a loop when an error is raised and continue with the next input of the loop?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to evaluate the bias of a particular function. To do this, I have a series of nested loops that change multiple input variables. Normally everything goes fine, but for a couple of combinations of inputs, the main function (qb.m) raises an error (below):
if (abs(2*z0) > abs(za))
error(' -- Decrease skew sensitivity. --');
end
My function just runs the qb.m function over and over again, records the outputs, and does a little calculation. When it hits an illegal combination, though, the main function ends execution and displays "Decrease skew sensitivity". Is there a way to make Matlab just move on to the next iteration of the loop instead of ending execution?
My code looks basically like this:
if true
for radfrac= Radfrac_min : Radfrac_step : Radfrac_max
for u=1:Max_training
for v=0:dimension;
for j=1:8
newspec = [compass_points(j,:)];
for i=1:z
B=50*i;
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] =qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias=sds-expected_standard_deviation(j);
SDS_matrix(((j-1)*z+i),:)=[compass_points(j,:),B,sds,bias,sdskew];
end
SDS_matrix
end
% Run that last block 5 more times, changing only the name
for j=1:8
newspec = [compass_points(j,:)];
for i=1:z
B=50*i;
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] =qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias=sds-expected_standard_deviation(j);
SDS_matrix(((j-1)*z+i),:)=[compass_points(j,:),B,sds,bias,sdskew];
end
SDS_matrix
end
%Average those six runs
%Do some calculations
%Store answers in a cell array
end end end end end
댓글 수: 0
채택된 답변
Matt Dickson
2018년 6월 12일
You should make your loop code inside a try/catch block and catch the error. It would look like
for i = 1:100 % whatever your loop is
try
% Your loop code here
catch
% Nothing should happen, just move on
continue;
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!