Index in position 1 exceeds array bounds (must not exceed 46)
2 views (last 30 days)
Show older comments
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';
0 Comments
Answers (1)
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
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.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!