Index exceeds the number of array error
Show older comments
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 Comments
Chunru
on 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
on 31 Mar 2022
Then x is a scaler and you cannot find x(idx) if idx is greater than 1.
Stephen23
on 31 Mar 2022
"x = 11 and y = 21 though"
And why do you expect that IDX should be able to index into scalar numerics?
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!