How to plot each state space variables seperatly

I created a state space system and I want to analyze the step response of each state space variable (x1, x2, x3...) seperatly. I'm not quite sure How am I suppose to access them. I've used the step command to creat vectors x and y, but I don't know how to creat a figure of x(t) (again, x1, x2, x3), and when Itry to access X or Y MATLAB tells me that the arrays are emptey, i would really like some help becasue I'm pretty new at MATLAB.
Thanks in advance!
My code so far:
A = [-1 4 0; 0 3 0; 0 0 -2];
B = [1 1 1];
B = transpose(B);
C = [-1 1 2];
sys = ss(A,[],C,[], 'StateName', {'x1' 'x2' 'x3'});
t = (0:0.1:5)';
[y, t, x] = step(sys,t);
plot(t, x(1));

回答(1 个)

Couple of things. First up, you haven't inserted B into your state-space model so consequently you don't get any output.
To get the individual states, just access the relevant column of the outputted x variable.
A = [-1 4 0; 0 3 0; 0 0 -2]; % note unstable, check eig(A)
B = [1 1 1]'; % note transpose
C = [-1 1 2];
sys = ss(A,B,C,[], 'StateName', {'x1' 'x2' 'x3'}); % note B is used !
t = [0:0.1:5]';
[y, t, x] = step(sys,t);
for i=1:3
subplot(3,1,i);
plot(t, x(:,i)); % look at how I indexed into x
end

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by