How to skip an input in a loop when an error is raised and continue with the next input of the loop?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cynthia Dickerson
le 12 Juin 2018
Commenté : 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 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 commentaires
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
% Your loop code here
catch
% Nothing should happen, just move on
continue;
end
end
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!