Recursive elimination of minimum number in a array
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Guillaume
2016년 11월 1일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!