# How to skip an input in a loop when an error is raised and continue with the next input of the loop?

1 vue (au cours des 30 derniers jours)
Cynthia Dickerson le 12 Juin 2018
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 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);
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);
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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Matt Dickson le 12 Juin 2018
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
catch
% Nothing should happen, just move on
continue;
end
end
##### 2 commentairesAfficher AucuneMasquer Aucune
Cynthia Dickerson le 12 Juin 2018
Do I need to do that for only the innermost loop?
Cynthia Dickerson le 12 Juin 2018
Thanks! You're my hero!!! That calculation is the last one I needed for my dissertation!!!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by