unique occurance table from array

1 回表示 (過去 30 日間)
Rahul Shelar
Rahul Shelar 2015 年 3 月 4 日
コメント済み: Star Strider 2015 年 3 月 4 日
I would like to be able to return the count of occurences of each element in a vector.
For example if I have a vector:
x=[10 25 4 10 9 4 4]
I expect the result to be
10 2
25 1
4 3
9 1

採用された回答

Star Strider
Star Strider 2015 年 3 月 4 日
Use the hist function:
x=[10 25 4 10 9 4 4];
ux = unique(x);
counts = hist(x, ux);
result = [ux' counts']
  4 件のコメント
Image Analyst
Image Analyst 2015 年 3 月 4 日
Also learn about its friends like histc() and imhist(). The histogram is like the PDF (probability distribution function), and related to that is the CDF, cumulative distribution function which you can get from passing the counts into cumsum(). By the way, hist() is now deprecated - they tell you to use histogram() instead.
Star Strider
Star Strider 2015 年 3 月 4 日
Note that Rahul Shelar is using Octave.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by