Index exceeds the number of array error
Ältere Kommentare anzeigen
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 Kommentare
Chunru
am 31 Mär. 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
am 31 Mär. 2022
Then x is a scaler and you cannot find x(idx) if idx is greater than 1.
Stephen23
am 31 Mär. 2022
"x = 11 and y = 21 though"
And why do you expect that IDX should be able to index into scalar numerics?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!