フィルターのクリア

find the number of occurances

1 回表示 (過去 30 日間)
johnson saldanha
johnson saldanha 2018 年 11 月 13 日
コメント済み: johnson saldanha 2018 年 11 月 13 日
my matrix is x=[ 1 1 1 3 3 4 4 4 6 7]
i want the output as y=[ 3 2 3 1 1]
i want to find how many times a particular value is occuring

採用された回答

Stephan
Stephan 2018 年 11 月 13 日
編集済み: Stephan 2018 年 11 月 13 日
y=sum(x(:)==unique(x))
Since 3 is occuring 2 times, the correct result is:
y=[3 2 3 1 1]
Best regards
Stephan
  6 件のコメント
Stephan
Stephan 2018 年 11 月 13 日
if you dont get it to work with this, use madhans code below.
johnson saldanha
johnson saldanha 2018 年 11 月 13 日
yeah i tried that it works. thank you

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 13 日
x=[ 1 1 1 3 3 4 4 4 6 7]
u = unique(x) %unique numbers
y=histc(x,u) %occurences
bonus = [u; y]' %relation between them
  2 件のコメント
johnson saldanha
johnson saldanha 2018 年 11 月 13 日
thanks.
madhan ravi
madhan ravi 2018 年 11 月 13 日
Anytime :)

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by