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

2 views (last 30 days)
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';

Answers (1)

Adam Danz
Adam Danz on 29 Jul 2020
Edited: Adam Danz on 29 Jul 2020
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 Comments
Shy
Shy on 29 Jul 2020
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 on 29 Jul 2020
Edited: Adam Danz on 29 Jul 2020
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!