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

2 次查看(过去 30 天)
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