Recursive elimination of minimum number in a array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Guillaume
am 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 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!