Borrar filtros
Borrar filtros

frequency of occurrence of the rows in a table

1 visualización (últimos 30 días)
sangeetha r
sangeetha r el 15 de En. de 2017
Comentada: sangeetha r el 16 de En. de 2017
I am attempting to count the number of times each row occurred in a table. i have the table( 5 row, 2 column)
a=
'b2' 'YE'
'b2' 'YE'
'b5' 'HN'
'b5' 'HN'
'b6' 'NV'
I want to get the output
b=
'b2' 'YE' 2
'b5' 'HN' 2
'b6' 'NV' 1
Is there anyway to solve this?

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 15 de En. de 2017
a = {'b2' 'YE'
'b2' 'YE'
'b5' 'HN'
'b5' 'HN'
'b6' 'NV'};
[a1,~,c] = unique(a,'stable');
cc = reshape(c,size(a));
[n,~,c1] = unique(cc,'rows','stable');
out = [a1(n),num2cell(histcounts(c1,1:max(c1)+1)')]
  1 comentario
sangeetha r
sangeetha r el 16 de En. de 2017
Thank you so much Andrei Bobrov. That solved my problem.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 15 de En. de 2017
Check out unique() with the 'rows' option.

Categorías

Más información sobre Numbers and Precision 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