Problem 45508. AK Sorting according to given order
Conventional ascending order of one digit number is [ 0, 1, 2, ......9]. Now this order is changed and stored in vector a. For example in a vector a = [3 8 7 5 0 9 2 1 6 4], first element 3 denotes the lowest value equal to 0 like in conventional representation and last element 4 denotes the highest value equal to 9 in conventional representation. Another vector b is unsorted one. You need to sort the vector b according the new order expressed by vector a. For a given vector b =[ 2 4 5 5 3 3 3 9 0] the sorted sequence is [3 3 3 5 5 0 9 2 4] and which should be stored in another vector named c.
Example : a= [ 3 8 7 5 0 9 2 1 6 4] % In this order '3' is considered as the smallest number and '4' is considered as largest number. b= [ 2 4 5 5 3 3 3 9 0] % This sequence is to be sorted according to the order in 'a'.
therefore, The should be, c=[3 3 3 5 5 0 9 2 4]
Comment: Consider both a & b are made using the digits from 0 to 9 only
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers18
Suggested Problems
-
Find the alphabetic word product
3330 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1100 Solvers
-
Find the Nth Root of a Given Number
309 Solvers
-
Element by element multiplication of two vectors
373 Solvers
-
There are 10 types of people in the world
1122 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!