필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Jamie Jenkinson
Jamie Jenkinson 2021년 4월 17일
댓글: Jamie Jenkinson 2021년 4월 17일
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