# Find indicies of k smallest matrix elements

13 views (last 30 days)
Brady Dean on 29 Sep 2020
Commented: madhan ravi on 29 Sep 2020
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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Xingwang Yong on 29 Sep 2020
[~, indices] = sort(A(:), 'ascend');
ind = indices(1:k);
##### 1 CommentShowHide None
Brady Dean on 29 Sep 2020
Ah, I forgot about the A(:) trick. This works perfectly.

Sign in to comment.

### More Answers (1)

Sindar on 29 Sep 2020
[~,idx] = mink(A,2);
##### 3 CommentsShowHide 2 older comments
madhan ravi on 29 Sep 2020
Unfortunately not everyone has the Crystal Ball.

Sign in to comment.

### Categories

Find more on Medical Physics 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!

Translated by