Recursive elimination of minimum number in a array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi All,
I have an array consisting of 4 groups: A=[1 1 1 2 2 1 1 1 2 2 3 3 4]. Here "1" appears six times, "2" four times, "3" twice and "4" once. In the first iteration, i should find the number that appears least number of times (in this case 4) and replace it with the next least appearing number (i.e replace 4 with 3). Then in the second iteration, the least appearing number is 3 so i should replace it with 2. Can someone please help with a simple code to do this?
0 commentaires
Réponses (1)
Guillaume
le 1 Nov 2016
Seems fairly straightforward to me. As I assume this is homework, I won't give you a complete solution but I'd use < unique> to get the list of unique numbers, a while loop based on the numel of values returned by unique and histcounts (with the option BinMethod, 'integers') to get the distribution of each numbers. sort that distribution and replace the first item by the second.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!