MATLAB Answers

How to force maltab to continue with next value of for loop index if it encounters NaN or infinity in the present loop.

조회 수: 4(최근 30일)
Amardeep Mishra
Amardeep Mishra 23 Oct 2018
댓글: Amardeep Mishra 23 Oct 2018
I have created an automate script to ease my pains of running my simulink simulation again and again manually. I pass the value to the simulink in each loop and let it run and save the generated graphs in a directory of my own. My problem is that the loop terminates abruptly whenever simulink encounters NaN! So, instead of taking the next loop index, it comes out of the loop prematurely without even completing all the indices over which for loop is running. Kindly help me. This is my very simple automate script:
for i=5:7
f = figure('visible','off');
rng(i)
theta_f_init=.1*rand(2,25);
rng(i)
theta_g_init=.1*rand(2,100);
sim('fuzzy_lafifi')
plot(error,'linewidth',2);
title('error');
set(f, 'Position', get(0, 'Screensize'));
k=num2str(i);
string=strcat('~/Desktop/yew/','error_afsmc_',k);
saveas(f,string,'png');
end

  댓글 수: 0

로그인 to comment.

답변(1개)

madhan ravi
madhan ravi 23 Oct 2018
편집: madhan ravi 23 Oct 2018
if ~isfinite(yourvariable(i))==1
continue
else
do this
end

  댓글 수: 11

표시 이전 댓글 수: 8
Amardeep Mishra
Amardeep Mishra 23 Oct 2018
Why do I need to write, theta_f.Data(i), I mean every time, theta_f.Data will be overwritten anyway.
Amardeep Mishra
Amardeep Mishra 23 Oct 2018
the size of theta_f is 2x25x10001, and it is this that is blowing up. My point is, the moment sim() encounters NaN it comes out of the for loop.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by