Counting number of iterations done in a numeric array

Hello! I'm new to Matlab and would like some help to get Matlab to count the numbers in an numeric array and then sort the 10 most frequent occurring numbers in descending order. Let's say the array consists of [24 12 10 24 8 8 24 13 13 13 13], I would like Matlab to order these like this 13 = 4 24 = 3 8 = 2 ...and so on.
Thank you! /Henrik

 채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 29일

0 개 추천

I suggest you see histc() and sort() and fprintf()

추가 답변 (1개)

Henrik
Henrik 2012년 1월 29일

0 개 추천

Hello again! Thank you Walter for you help! However, I don't manage Matlab to only print 10 values. It gets printed in descending order but all the values not only the 10 most occurring ones. Should I fix that in sort(), or fprintf()?
Thank you! /Henrik

댓글 수: 1

You can discard everything after the 10th element, or you can simply choose to print only the first 10 elements.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by