How do I pull data from a FOR LOOP and save into vector.

2 views (last 30 days)
This is what i have so far. I just cant seem to pull out the data from each run through the loop to compile a vector showing all values of K that satisfy each condition.
% Problem #3 Transient response
% A). Write a loop to test integer values of K over the range of values
% of K <= 200 that do not produce right-half-plane roots
% B). The loop should contain:
% i. Determine the closed-loop system poles using the "pole" command.
% ii. Test for an underdamped step response, using the "isreal"
% command.
% iii. Store those values of K that produce an underdamped step
% response in a vector. Display this vector in the Command Window.
% iv. Plot in Figure 2 (using the "figure" command) the unit step
% response for the largest gain K that gives an underdamped step
% response.
% v. Test for a critically-damped step response, using the "real"
% and "isreal" command.
% vi. Store those values of K that produce a critically-damped step
% response in a vector. Display this vector in the Command Window.
% vii. Plot in Figure 3 (using the "figure" command) the unit step
% response for the gain K that gives a critically-damped step
% response.
% viii. Test for an overdamped step response, using the real and
% isreal command.
% ix. Store those values of K that produce an overdamped step
% response in a vector. Display this vector in the Command Window.
% x. Plot in Figure 4 (using the "figure" command) the unit step
% response for the smallest gain K that gives an overdamped step
% response.
disp('Values of "K" that do NOT return RHP roots')
for k2=[1:1:200];
G2=tf(k2*5,[1 10 -200]);
Ge2=feedback(G2,1);
p2=pole(Ge2)
r2=real(p2);
if max (r2) < 0;
k2;
fprintf('value of "k" = %1.1f \n',k2);
end
end
  1 Comment
per isakson
per isakson on 4 Apr 2015
Add these two lines to the code
K = nan( 1, 200 );
K(k2)=k2;
Caveat: I didn't read all the comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!