How to count the frequency of each type of column vector present in a matrix

4 ビュー (過去 30 日間)
Radu Mihail
Radu Mihail 2021 年 3 月 18 日
コメント済み: David Hill 2021 年 3 月 19 日
I have a matrix R(21,3)
R=[1,1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1;1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1;1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1,1];
and I would like to count the frequency of each column vector present from the whole matrix. For instance column vector a=[2,2,2]' is present 3 times, vector b=[2,2,1]' is present 3 times, vector c=[1,4,2]' is present only once. A table with all column vectors and their frequency.

採用された回答

David Hill
David Hill 2021 年 3 月 18 日
R=[1,1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1;1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1;1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1,1];
a=[2 2 2];
nnz(ismember(R',a,'rows'));
  4 件のコメント
Radu Mihail
Radu Mihail 2021 年 3 月 19 日
I am sorry this is just to identify unique vectors. I do not follow and I do not understand how to get the table of all column vector frequencies distributions in the matrix. I need something like this
1 1 1 2 2 2 1 2 2 1 4 2 2 2 2 1 2 1 3 1 1
1 1 2 2 2 1 2 2 1 4 2 2 2 2 1 2 1 3 1 1 1
1 2 2 2 1 2 2 1 4 2 2 2 2 1 2 1 3 1 1 1 1
Frequency of column vector(mentioned once)
------------------------------------------------------------------------------------
3 1 2 3 3 2 - - 1 1 1 - - - - 1 1 1 1 - -
David Hill
David Hill 2021 年 3 月 19 日
R=[1,1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1;1,1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1;1,2,2,2,1,2,2,1,4,2,2,2,2,1,2,1,3,1,1,1,1];
[r,idx]=sort(sum(R.*[13;17;19]));%choose primes such that the number of repetitions of each will not exceed
[rr,idx2]=unique(r);
numberOfeachUniqueR=histcounts(r,[rr,r(end)+1]);%generates the number of occurrances of each unique triplet
UniqueR=R(:,idx(idx2));%generates cooresponding unique tripets (just like your output above)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by