How can I find the n smallest numbers in a two-dimensional array of m numbers?

1 Ansicht (letzte 30 Tage)
For example, with this 2x5 matrix (m=10 and n=4), the expected answer is
(2,9), (1,5), (1,3), (2,10)
111 , 112, 145, 212
236 245 145 244 112
225 232 266 111 212

Akzeptierte Antwort

Iman Ansari
Iman Ansari am 13 Apr. 2013
Hi.
n=4;
a=[236 245 145 244 112; 225 232 266 111 212];
[r c]=size(a);
a = a';
vector=a(:);
[B,IX] = sort(vector);
[fix((IX(1:n)-1)./c)+1 IX(1:n)]

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by