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

조회 수: 1 (최근 30일)
Patrick Scott
Patrick Scott 2021년 11월 11일
댓글: 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:
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

채택된 답변

Paul
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
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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by