Is it possible to skip for loop when error appears and replace the results with NaN?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Jaladhar Mahato
il 11 Lug 2018
Commentato: Jaladhar Mahato
il 11 Lug 2018
I have a 3D matrix ( Auto) and in which I am fitting the Auto(p,q,:) elements using a for a loop. I am calculating one parameter ( D(p,q)=fit1.D) from the fitting. However, due to some reason ( Complex value computed by model function, fitting cannot continue), fitting is not happening for some p,q and hence the for loop terminated. Here I want to put D(p,q)=NaN when the fitting gives the error and want to proceed for next loop.
Thanks in advance for your help.
l2= size(Auto);
for p=1:l2(1)
for q=1:l2(2)
y=reshape(Auto(p,q,2:end),[],1);
x=(0:0.5:(35-1)*0.5)';
f = fittype('(A./(sqrt(1+ ((x*D)./(0.251.^2)))))');
fit1 = fit(x,y,f,'StartPoint',[0.1 0.1 ]);
D(p,q)=fit1.D;
% D(p,q)=NaN;
end
end
0 Commenti
Risposta accettata
James Tursa
il 11 Lug 2018
Something like this?
try
% your fitting stuff goes here
D(p,q) = fit1.D;
catch
D(p,q) = NaN;
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!