フィルターのクリア

Help With for loop with tranfer function and step

1 回表示 (過去 30 日間)
Davide Cannavacciuolo
Davide Cannavacciuolo 2023 年 11 月 20 日
コメント済み: Sam Chak 2023 年 11 月 20 日
s=tf('s');
G=1/(s^2+0.4*s+0.1);
K=[1 2 3 4 5 6];
figure
hold on
for i=1:1:length(K)
T=K(i)*G;
step(T)
S=stepinfo(T);
L=S.Peak(T)
end
I have this code but i get the error : "Unable to use a value of type tf as an index."
I want actually to make a vector containg all the values of the peak values and only then plot the peaks with the corresponding value of gain.
Thank you in advance

採用された回答

Sam Chak
Sam Chak 2023 年 11 月 20 日
You probably want to plot like this:
s = tf('s');
G = 1/(s^2 + 0.4*s + 0.1);
K = [1 2 3 4 5 6];
figure(1)
hold on
for i = 1:length(K)
T = K(i)*G;
step(T)
S = stepinfo(T);
L(i) = S.Peak;
end
grid on
hold off
figure(2)
plot(K, L, '-o'), grid on
xlabel('Gain'), ylabel('Peak')
  2 件のコメント
Davide Cannavacciuolo
Davide Cannavacciuolo 2023 年 11 月 20 日
Thank you so much!
Sam Chak
Sam Chak 2023 年 11 月 20 日
Ciao @Davide Cannavacciuolo. You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 11 月 20 日
編集済み: Dyuman Joshi 2023 年 11 月 20 日
There is no field in the struct 'S' with name 'T'. Thus you get the error in the line you defined 'S'.
I suspect that you want to get the 'Peak' value for each system -
s=tf('s');
G=1/(s^2+0.4*s+0.1);
K=[1 2 3 4 5 6];
%Preallocation
L = K.*0;
figure
hold on
for i=1:1:length(K)
T=K(i)*G;
step(T);
S=stepinfo(T);
L(i)=S.Peak;
end
L
L = 1×6
10.7689 21.5379 32.3068 43.0757 53.8447 64.6136

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by