I'd like to make several 'figure' window

2 ビュー (過去 30 日間)
가현
가현 2024 年 5 月 22 日
コメント済み: 가현 2024 年 5 月 22 日
I want to add two figure windows, but <figure 2> window doesn't show up.
<code>
%상태 방정식
%Dx1 = -x1 - x2 + u1 + u2
%Dx2 = 6.5*x1 + u1
%y1 = x1
%y2 = x2
t = 0:0.01:15;
A = [-1 -1;6.5 0];
B = [1 1;1 0];
C = [1 0;0 1];
D = [0 0;0 0];
sys = ss(A,B,C,D);
impulse(sys,t);
[y,t,x] = impulse(sys,t);
y1 = [1 0]*y(:,:,1)' + [1 0]*y(:,:,2)';
y2 = [0 1]*y(:,:,1)' + [0 1]*y(:,:,2)';
figure(1)
plot(t,sys)
xlabel('Time,(s)')
ylabel('y')
grid;
legend('y')
figure(2)
subplot(211);
plot(t, y1); grid
ylabel('y_1')
subplot(212);
plot(t, y2); grid
xlabel('t (sec)'); ylabel('y_2')

採用された回答

Infinite_king
Infinite_king 2024 年 5 月 22 日
編集済み: Infinite_king 2024 年 5 月 22 日
Hi 가현,
The following expression 'plot(t,sys)' will result in an error since 'sys' is a dynamic system model, and the 'plot' function will not accept a model as input. The line 'plot(t,sys)' can be removed because the 'impulse' function plots the impulse response of 'sys'
t = 0:0.01:15;
A = [-1 -1;6.5 0];
B = [1 1;1 0];
C = [1 0;0 1];
D = [0 0;0 0];
sys = ss(A,B,C,D);
impulse(sys,t); % this syntax will plot the impulse response
[y,t,x] = impulse(sys,t);
y1 = [1 0]*y(:,:,1)' + [1 0]*y(:,:,2)';
y2 = [0 1]*y(:,:,1)' + [0 1]*y(:,:,2)';
figure(1)
% plot(t,sys)
xlabel('Time,(s)')
ylabel('y')
grid;
legend('y')
figure(2)
subplot(211);
plot(t, y1); grid
ylabel('y_1')
subplot(212);
plot(t, y2); grid
xlabel('t (sec)'); ylabel('y_2')
For more information on 'impulse' function, refer the following MATLAB documentation - https://www.mathworks.com/help/ident/ref/dynamicsystem.impulse.html
  1 件のコメント
가현
가현 2024 年 5 月 22 日
Thank you for your kind reply. This helped me solve my problem!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by