index exceeds matrix dimensions

1 visualización (últimos 30 días)
sani ars
sani ars el 29 de Sept. de 2012
Comentada: Walter Roberson el 21 de Mayo de 2019
what does this error means??...
"index exceeds matrix dimensions"
  2 comentarios
Matt J
Matt J el 21 de Mayo de 2019
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 el 21 de Mayo de 2019
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.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 29 de Sept. de 2012
Editada: Matt J el 30 de Sept. de 2012
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.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by