Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Clayton Gotberg
Clayton Gotberg am 17 Apr. 2021
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).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Fletcher
David Fletcher am 17 Apr. 2021
Bearbeitet: David Fletcher am 17 Apr. 2021
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 Kommentar
Jamie Jenkinson
Jamie Jenkinson am 17 Apr. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by