I'd like to make several 'figure' window

2 vues (au cours des 30 derniers jours)
가현
가현 le 22 Mai 2024
Commenté : 가현 le 22 Mai 2024
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')

Réponse acceptée

Infinite_king
Infinite_king le 22 Mai 2024
Modifié(e) : Infinite_king le 22 Mai 2024
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 commentaire
가현
가현 le 22 Mai 2024
Thank you for your kind reply. This helped me solve my problem!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by