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

1 visualización (últimos 30 días)
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 comentario
Clayton Gotberg
Clayton Gotberg el 17 de Abr. de 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).

Iniciar sesión para comentar.

Respuesta aceptada

David Fletcher
David Fletcher el 17 de Abr. de 2021
Editada: David Fletcher el 17 de Abr. de 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 comentario
Jamie Jenkinson
Jamie Jenkinson el 17 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by