Problem 38. Return a list sorted by number of occurrences
Given a vector x, return a vector y of the unique values in x sorted by the number of occurrences in x.
Ties are resolved by a sort from lowest to highest.
So if
x = [1 2 2 2 3 3 7 7 93]
then
y = [2 3 7 1 93]
Solution Stats
Problem Comments
-
2 Comments
Chul Min Yeum
on 3 Jan 2020
Good problem!
Ahmed Nazir
on 30 Sep 2020
It is easy if you use matlab function...
useful function ==> categorical, countcats , sort, unique
solution:
https://github.com/AhmedNazir/MatlabCody/blob/master/popularity.m
Solution Comments
Show commentsProblem Recent Solvers2776
Suggested Problems
-
5600 Solvers
-
Find the peak 3n+1 sequence value
2498 Solvers
-
1408 Solvers
-
Get the length of a given vector
10948 Solvers
-
Switch matrix to a column vector
349 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!