How can I call an array of letters into a for loop?
2 ビュー (過去 30 日間)
コメント済み: Patrick Scott 2021 年 11 月 11 日
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:
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)
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))
marg = allmargin(L);
if marg.Stable == 1
fprintf('Closed loop system is stable for part %f.', letters(i))
fprintf('The closed loop system is not stable for part%f.', letters(i))
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)
Paul 2021 年 11 月 11 日
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
その他の回答 (0 件)
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!