How can I call an array of letters into a for loop?

2 views (last 30 days)
I would like to setup this for loop to output each interation of with the coorasponding part of my homework. I can do it all individually but that doesn't seem efficient. Every way I have tried outputs to cooresponding integer and not the actual character (a,b,c,d)
I would like it to read:
The open loop poles for part c are:
ans =
0
-10
-10
Closed loop system is stable for part c.
Gain Margin for part c is: 20.000000.
Phase Margin part c is: 78.689008.
Time delay Margin for part c is: 1.386851.
k = [200 100 100 80];
a = [1 1 0 1];
z = [1 0.1 1 1];
w = 10;
s = tf('s');
C = [65 66 67 68];
letters = char(C)
for i=1:4
L = k(i)/ ((s+a(i))*(s^2 + 2*z(i)*w*s + w^2));
[top, bottom] = tfdata(L);
fprintf('The open loop poles for part %f are:\n', letters(i))
roots(bottom{1})
marg = allmargin(L);
if marg.Stable == 1
fprintf('Closed loop system is stable for part %f.', letters(i))
fprintf('\n\n')
else
fprintf('The closed loop system is not stable for part%f.', letters(i))
fprintf('\n')
end
fprintf('Gain Margin for part %f is: %f.\n', letters(i) , marg.GainMargin)
fprintf('Phase Margin for part %f is: %f.\n', letters(i) , marg.PhaseMargin)
fprintf('Time delay Margin for part %f is: %f.\n\n', letters(i) , marg.DelayMargin)
end

Accepted Answer

Paul
Paul on 11 Nov 2021
If I understand the question ....
letters = 'ABCD'; % simpler
for ii = 1:4
fprintf('The open loop poles for part %s are:\n', letters(ii)) % use s not f as the format
end
The open loop poles for part A are: The open loop poles for part B are: The open loop poles for part C are: The open loop poles for part D are:

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!