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

조회 수: 1 (최근 30일)
Shy
Shy 2020년 7월 29일
편집: Adam Danz 2020년 7월 29일
Hi,
I am getting this error in my code: Can you please help me with this problem?
Index in position 1 exceeds array bounds (must not exceed 46).
Error in testfile (line 58)
y(n,:)=feval('Fun',T(n),Y(n,:),D(n,:));
Y is 617 by 4 matrix, T is 617 by 1 matrix, D is 46 by 16 matrix
[rY cY]=size(Y);
for n=1:rY
for m=1:cY
y(n,:)=feval('Fun',T(n),Y(n,:),D(n,:));
end
end
y=y';

답변 (1개)

Adam Danz
Adam Danz 2020년 7월 29일
편집: Adam Danz 2020년 7월 29일
The value of n iterates from 1 to 617.
The size of D is 46x16.
When n=47, you get the error because D(47,:) doesn't exist. The last row of D is 46.
y(n,:)=feval('Fun',T(n),Y(n,:),D(n,:));
% ^^^^^^
Hence, 'Index in position 1 exceeds array bounds (must not exceed 46).'
  댓글 수: 4
Shy
Shy 2020년 7월 29일
The actual sizes of T, Y and D are correct. But how can I do the indexing in a right way? Thanks
Adam Danz
Adam Danz 2020년 7월 29일
편집: Adam Danz 2020년 7월 29일
I don't know. I can't know. Again, the problem needs to be solved at the conceptual level.
I don't know what the function is supposed to be doing.
You need to think about what the function is supposed to be doing and forget about code for a moment.
What should the inputs look like, their shape and size?
How are the T Y and D variables supposed to be combined as inputs?
What does the fun function expect to receive?
These are higher level questions to think about.

댓글을 달려면 로그인하십시오.

카테고리

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