How can I find the indices of the 3 largest values in my matrix?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a matrix with varying values. I want to find the 3 largest values in this matrix and assign their indices to 3 different variables. How can I do this as simply as possible? Example matrix:
99 45 93 64
12 83 24 85
39 71 29 13
After finding the largest values - 99,93,85. I'd like to find their respective indices (with linear indexing). So that would be 1,7,11.
a = 1;
b = 7;
c = 11;
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 7 de Mayo de 2013
A = [99 45 93 64;
12 83 24 85
39 71 29 13];
[ii,ii] = sort(A(:),'descend');
out = ii(1:3);
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!