Find indicies of k smallest matrix elements

10 次查看(过去 30 天)
I'm trying to find the indicies of smallest k matrix elements.
For example if I have
A = [10 5 2; 34 5 21; 4 6 8];
and I want to find the smallest 2 elements indicies then I want indicies 7 and 3.

采纳的回答

Xingwang Yong
Xingwang Yong 2020-9-29
[~, indices] = sort(A(:), 'ascend');
ind = indices(1:k);

更多回答(1 个)

Sindar
Sindar 2020-9-29
[~,idx] = mink(A,2);
  3 个评论
Brady Dean
Brady Dean 2020-9-29
I'm using R2020b, that's the newest isn't it?
mink gives minimums over a dimension, not the whole matrix. Sindar's code doesn't work for my example above.
madhan ravi
madhan ravi 2020-9-29
Unfortunately not everyone has the Crystal Ball.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by