How to make a code continue running if while loop returns NaN

5 vues (au cours des 30 derniers jours)
Adeyemi Adepegba
Adeyemi Adepegba le 11 Juil 2011
I have the following code below
R =5; % LQR Weighting
Q = [100 0 0 0; 0 5 0 0; 0 0 10 0; 0 0 0 1];
K = dlqr(Adhat,Bdhat,Q, R);
R1a = tf(ss(Adhat,Bdhat,K,0));
T1a = minreal(minreal(R1a)/(1 + minreal(R1a))); % Closed Loop Transfer Function
figure(1)
step(T1a)
S = stepinfo(T1a,'SettlingTimeThreshold',0.01); %Settling time threshold specification for 1%
x = S.SettlingTime;
while x > 0.1
R=R/2;
Q = Q*2;
K = dlqr(Adhat,Bdhat,Q, R);
R1a = tf(ss(Adhat,Bdhat,K,0));
T1a = minreal(minreal(R1a)/(1 + minreal(R1a)));
figure(1)
step(T1a)
hold on
x1 = 0:0.1:20; y1 = 1.01*ones(size(x1)); line(x1,y1) % Line to indicate +1%
x2 = 0:0.1:20; y2 = 0.99*ones(size(x2)); line(x2,y2) % Line to indicate -1%
hold off
S = stepinfo(T1a,'SettlingTimeThreshold',0.01); %Settling time threshol specification for 1%
x = S.SettlingTime;
end
figure(2)
nyquist(R1a)
title('Nyquist diagram of return ratio, K ')
hold on
circ = -1 +exp(j*[0:pi/1000:2*pi]');
plot(circ,'r')
hold off
disp('See Fig 2')
disp(['Settling Time= ' num2str(x)])
disp(['R= ' num2str(R)])
disp(['K= ' num2str(K)])
I need the code to continue running even if the while loop returns a NaN value, I cant seem to get this to work. I have tried using if else loop and it returns the same result.
I will apprciate any tips to get this issue resolved.
Thanks
  1 commentaire
Jan
Jan le 11 Juil 2011
Please format your code properly. See the "Markup" link on this page for explanations.
It would be easier to answer, if you omit all lines, which do not concern your problem. A WHILE loop does not return anything, so please explain, where the NaN appears. Do you mean, that x gets the value NaN?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 11 Juil 2011
I have only a faint idea of what your problem might be. Perhaps this helps:
while (x > 0.1) || isnan(x)
  1 commentaire
Adeyemi Adepegba
Adeyemi Adepegba le 11 Juil 2011
Excellent answer, that solved the problem.
I dont understand your comment about editing the code.

Connectez-vous pour commenter.

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 11 Juil 2011
while something || isnan(something_else)
%etc.
end

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!

Translated by