Index exceeds the number of array error
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sashi Mendoza
il 31 Mar 2022
Modificato: Sashi Mendoza
il 3 Apr 2022
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 Commenti
Stephen23
il 31 Mar 2022
"x = 11 and y = 21 though"
And why do you expect that IDX should be able to index into scalar numerics?
Risposta accettata
Arif Hoq
il 31 Mar 2022
Modificato: Arif Hoq
il 31 Mar 2022
var = randi(100,20,20);
[val,idx] = max(var(:))
[x, y] = find(var == val)
idx2=2;
x0 = x(idx2)
y0 = y(idx2)
here your idx=2(intentionally fixed) and your number of element of x and y is 7. so x0 and y0 can extract from index 2. now see the below example
%%
var = randi(100,20,20);
[val,idx] = max(var(:))
[x, y] = find(var == val)
% idx2=2;
x0 = x(idx)
y0 = y(idx)
here your idx=18, but your number of element of x and y is 5.so it can not extract form index 18. therefore, you are getting error.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!