How to make unique vector with probability of elements?

1 回表示 (過去 30 日間)
sia ben
sia ben 2018 年 7 月 5 日
コメント済み: sia ben 2018 年 7 月 5 日
I have a matrix A= [22 1;24 0; 23 1; 24 1; 22 1]. I want to drive a new matrix like below: B= [22 1;23 1;24 0.5] in which the first column is the "unique" of A and the second column is the probability of these elements. That means the every of second column elements of similar first columns in A: - in A there are two rows with 22 and both of them have probability of 1, that means in B 22 has probability of 1 - But for 24 there is two different 0 and 1. So in B it must be 0.5.

採用された回答

Matt J
Matt J 2018 年 7 月 5 日
B=splitapply(@(z)mean(z,1), A, findgroups(A(:,1)))
  1 件のコメント
sia ben
sia ben 2018 年 7 月 5 日
Thanks it works well1!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by