フィルターのクリア

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 Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by