How to find the frequency of unique rows in 3 columns of a table?

1 回表示 (過去 30 日間)
Denis Pesacreta
Denis Pesacreta 2018 年 6 月 25 日
コメント済み: Denis Pesacreta 2018 年 6 月 26 日
I have a table (T) of the following form:
Var1 Var2 Var3
Car Red X
Dog Blue Y
Car Red X
TV Green Z
TV Yellow Z
TV Green Z
Car Red X
Where for example the first row is T.Var1(1)=Car, T.Var2(1)=red, T.Var3(1)= X.
I would like to return
Var1 Var2 Var3 Var4
Car Red X 3
Dog Blue Y 1
TV Green Z 2
TV Yellow Z 1
Any assistance you can provide is much appreciated!

採用された回答

Paolo
Paolo 2018 年 6 月 25 日
編集済み: Paolo 2018 年 6 月 26 日
Var1 = {'Car';'Dog';'Car';'TV';'TV';'TV';'Car'}
Var2 = {'red';'blue';'red';'green';'yellow';'green';'red'};
Var3 = {'X';'Y';'X';'Z';'Z';'Z';'X'};
t = table(Var1,Var2,Var3);
[tt ia ic] = unique(t);
Var4 = histc(ic,unique(ic));
tt.Var4 = Var4;
tt is the required table.
  1 件のコメント
Denis Pesacreta
Denis Pesacreta 2018 年 6 月 26 日
Thank you so much! It worked perfectly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by