I'd like to make several 'figure' window

2 visualizzazioni (ultimi 30 giorni)
가현
가현 il 22 Mag 2024
Commentato: 가현 il 22 Mag 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')

Risposta accettata

Infinite_king
Infinite_king il 22 Mag 2024
Modificato: Infinite_king il 22 Mag 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 Commento
가현
가현 il 22 Mag 2024
Thank you for your kind reply. This helped me solve my problem!

Accedi per commentare.

Più risposte (0)

Tag

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by