how to track location of number in array after sorting?

i have a array B=[ 95 75 80 90 40 55] which i want to save data like B=[B1 B2 B3 B4 B5 B6] after sorting i got B=[95 90 80 75 55 40] now i want the exact location of B array like B=[B1 B4 B3 B2 B6 B5] want to know changed location and also want to use the numeric value of B1 for example want to save in n=1 to use for selection purpose.

 Accepted Answer

[~,Wanted] = sort(B,'descend')

7 Comments

can you please show by applying in code?
>> B=[ 95 75 80 90 40 55]
B =
95 75 80 90 40 55
>> [sorted_B,retriever] = sort(B,'descend')
sorted_B =
95 90 80 75 55 40
retriever =
1 4 3 2 6 5
>> original_B = sorted_B(retriever)
original_B =
95 75 80 90 40 55
>>
if we want to use the value of
retriever =
1 4 3 2 6 5
or want to save in array is there seperate command for this?
It's already saved in an array. Or do you mean like a data file?
great thanks for your help. it is very kind of you giving me reply

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!