How can I call an array of letters into a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!