Index exceeds the number of array error
Afficher commentaires plus anciens
a = a certain 20x20 matrix;
[val,idx] = max(a(:));
[x, y] = find(a == val);
At the underlined part of the code, this displays the error "Index exceeds the number of array elements (1)". How to fix this?
3 commentaires
Chunru
le 31 Mar 2022
The result of 'find' may be empty so that x and y are empty. However idx is a positive number. This cause the problem.
Chunru
le 31 Mar 2022
Then x is a scaler and you cannot find x(idx) if idx is greater than 1.
Stephen23
le 31 Mar 2022
"x = 11 and y = 21 though"
And why do you expect that IDX should be able to index into scalar numerics?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!