Select a certain number of mine Vector Members in MATLAB

Hi
I have a 40 x 1 vector. I want to find the location of 20 smaller components of this vector. The position of these members is considered.
Thanks for your guidance

 Accepted Answer

Let v be your vector. You can arrange them from small to big order i.e in ascending order and then pick first twenty elements.
[val,idx] = sort(v) ;
val(1:20) % values
idx(1:20) % indices

3 Comments

thank you
But for me, their position is important. By arranging the vector, their original positions change
Because the goal is to understand the position of these members and then using their position number from another matrix I will select the corresponding rows
You already have the indices in your hand as idx which corresponds to original vector. This is not a problem. The positions are according to vector v.

Sign in to comment.

More Answers (0)

Categories

Find more on Software Development in Help Center and File Exchange

Products

Release

R2019b

Tags

Asked:

on 6 Oct 2020

Commented:

on 6 Oct 2020

Community Treasure Hunt

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

Start Hunting!