Index in position 2 exceeds array bounds (must not exceed 1).

1 次查看(过去 30 天)
clc
A= [ -0.0240 -9.5113 0 -0.2973
0.0010 -1.1746 0 1.1758
0 2.3532 -0.9461 -2.3532
0 0 1.0000 0];
B = [0.8 0; 0 0; 0 -2.39; 0 0];
C = [1 0 0 0];
D = [0 0];
sys_1=ss(A,B,C,D);
[n1,d1]=ss2tf(A,B,C,D,2);
time = 0:0.005:10;
figure(1);
y_v=step(sys_1,time);
V_Plot=plot(time,y_v(:,2,1),'LineWidth',2);
ylabel('(m/s)');
xlabel('(s)');
title('V');
grid on;
Index in position 2 exceeds array bounds (must not exceed 1).
Error in SS2TF (line 14)
V_Plot=plot(time,y_v(:,2,1),'LineWidth',2);
Im trying to run this code. Im looking to extract data from the four columns of matrix A, and the 2 columns of matrix B. I thought this was done using the (:,:,:) after the step of the plot but I keep getting an error saying ive exceeded array bounds. I thought there was a way I can get the (muse not exceed) to 4, and 2 if that makes sense. However it wont let me exceed 1 for both. Any help is appreciated
  1 个评论
Clayton Gotberg
Clayton Gotberg 2021-4-17
What size is y_v? MATLAB's step command should only return one state at a time with the inputs you've supplied here.
If you want multple states, change the output matrix C from [1 0 0 0] (outputting only the first state) to something like [1 0 0 0; 0 1 0 0] (outputting the first and second states).

请先登录,再进行评论。

采纳的回答

David Fletcher
David Fletcher 2021-4-17
编辑:David Fletcher 2021-4-17
y_v is 2001x1x2 - you are trying to index the second column which does not exist. Do you mean this?
clc
A= [ -0.0240 -9.5113 0 -0.2973
0.0010 -1.1746 0 1.1758
0 2.3532 -0.9461 -2.3532
0 0 1.0000 0];
B = [0.8 0; 0 0; 0 -2.39; 0 0];
C = [1 0 0 0];
D = [0 0];
sys_1=ss(A,B,C,D);
[n1,d1]=ss2tf(A,B,C,D,2);
time = 0:0.005:10;
figure(1);
y_v=step(sys_1,time);
V_Plot=plot(time,y_v(:,1,2),'LineWidth',2);
ylabel('(m/s)');
xlabel('(s)');
title('V');
grid on;
this gives
  1 个评论
Jamie Jenkinson
Jamie Jenkinson 2021-4-17
Yes this is perfect thank you. I somehow managaed to make y_v 2001x4x2 and hence was allowed to use the second array of 4.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by