Borrar filtros
Borrar filtros

finding the frequency of each row (2)

2 visualizaciones (últimos 30 días)
Mnr
Mnr el 29 de Mzo. de 2014
Respondida: Azzi Abdelmalek el 29 de Mzo. de 2014
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.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Mzo. de 2014
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]

Más respuestas (1)

Walter Roberson
Walter Roberson el 29 de Mzo. de 2014
You can get the counts using accumarray(A + 2, 1, [3 3])

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by