필터 지우기
필터 지우기

frequency of occurrence of the rows in a table

조회 수: 1 (최근 30일)
sangeetha r
sangeetha r 2017년 1월 15일
댓글: sangeetha r 2017년 1월 16일
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?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 1월 15일
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
sangeetha r
sangeetha r 2017년 1월 16일
Thank you so much Andrei Bobrov. That solved my problem.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 1월 15일
Check out unique() with the 'rows' option.

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by