index exceeds matrix dimensions

1 回表示 (過去 30 日間)
sani ars
sani ars 2012 年 9 月 29 日
コメント済み: Walter Roberson 2019 年 5 月 21 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by