フィルターのクリア

finding the frequency of each row (2)

2 ビュー (過去 30 日間)
Mnr
Mnr 2014 年 3 月 29 日
回答済み: Azzi Abdelmalek 2014 年 3 月 29 日
Hello all,
Per my previous question, I have several mx2 matrices with rows from (0,1), (-1,0), (0,1), (0,-1), (1,1), (-1,1), (1,-1),(-1,-1) and I would like to find the frequency of each of above coordinates, I used unique and hisc to give me the frequency of each row. Now, since I would like to compare different matrices, I would like for each matrix have a corresponding output of 8 rows, where each row indicates the number of times that each of above coordinates appear. In particular, if e.g (0,1) is not among the rows of my matrix, I would like to see zero frequency.
For instance, if A=[1 1; 0 1; 1 0; -1 1;-1 1;0 1;0 1]
I would like to see something like:
-1 -1 0
-1 0 0
-1 1 2
0 -1 0
0 1 3
1 -1 0
1 0 1
1 1 1
Is there a way to do it? Thanks.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 29 日
B=[-1 -1
-1 0
-1 1
0 -1
0 1
1 -1
1 0
1 1]
A==[1 1; 0 1; 1 0; -1 1;-1 1;0 1;0 1]
[ii,jj,kk]=unique(A,'rows')
f1=histc(kk,1:numel(jj));
f=zeros(size(B,1),1);
idx=ismember(B,ii,'rows');
M=[B zeros(size(B,1),1)];
M(idx,:)=[ii f1]

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 3 月 29 日
You can get the counts using accumarray(A + 2, 1, [3 3])

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by