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';
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!