index exceeds matrix dimensions

1 次查看(过去 30 天)
sani ars
sani ars 2012-9-29
what does this error means??...
"index exceeds matrix dimensions"
  2 个评论
Matt J
Matt J 2019-5-21
Simon Emery's comment moved here:
Hi, i got the same issue.
I have 3 matrix. the first one is for data vector in matrix [1 2 3 12 11 6 7 8 9 10], the second is for the ii [1 2 3 3 3 7 7 8 9 10] and the last matrix is for the jj (column) [10 2 3 6 8 1 7 3 9 6]
when i creat my function and launch a test with this approach it is work properly... well at least... SOMEONE COULD HELP ME?
afficheMatriceCreuse([1 2 3 12 11 6 7 8 9 10], [1 2 3 3 3 7 7 8 9 10],[10 2 3 6 8 1 7 3 9 6])
i got this error message:
(1,10) 1
(2,2) 2
(3,3) 3
(3,6) 12
(3,8) 11
(7,1) 6
(7,7) 7
(8,3) 8
(9,9) 9
(10,6) 10
Index exceeds matrix dimensions.
Error in afficheMatriceCreuse (line 31)
fprintf('(%i,%i) %i \n', iM(ii),jM(ii),vM(ii))
or Index exceeds matrix dimensions.
Error in afficheMatriceCreuse (line 26)
iM(ii);
Function:
function afficheMatriceCreuse(vM,iM,jM)
for ii = 1:(numel(iM,jM,vM))
(line26) iM(ii);
jM(ii);
vM(ii);
(line31) fprintf('(%i,%i) %i \n', iM(ii),jM(ii),vM(ii))
end
end
Walter Roberson
Walter Roberson 2019-5-21
for ii = 1:(numel(iM,jM,vM))
numel with multiple arguments has undocumented results. It looks to me as if it returns the product of the number of elements of the arguments after the first.
>> numel(1:50,[3 4 5],[3 4; 5 3])
ans =
12
That is, size and content of the first argument was ignored, and the number of elements of the second argument (3) was multipled by the number of elements of the third argument (4) to get the result.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2012-9-29
编辑:Matt J 2012-9-30
It means you've done something similar to this:
>> x=1:5
x =
1 2 3 4 5
>> y=x(6)
Attempted to access x(6); index out of bounds because numel(x)=5.

类别

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