How to obtain the unique combinations of two columns in a table

99 ビュー (過去 30 日間)
Blue
Blue 2019 年 8 月 9 日
コメント済み: Blue 2019 年 8 月 9 日
Hi,
I am trying to obtain all the unique combinations of two columns in a table. Lets say we have the following table:
year = {1994, 1994, 1994, 1995, 1995, 1995, 1996, 1996, 1996}.';
type = {'AA', 'BB', 'CC', 'BB', 'BB', 'BB', 'AA', 'CC', 'CC'}.';
t = table(year, type);
How can I extract the unique combinations of 'year' and 'type' in order to get something like this:
year = {1994, 1994, 1994, 1995, 1996, 1996}.';
type = {'AA', 'BB', 'CC', 'BB', 'AA', 'CC'}.';
answer = table(year, type);
Thank you

採用された回答

dpb
dpb 2019 年 8 月 9 日
year = [1994, 1994, 1994, 1995, 1995, 1995, 1996, 1996, 1996].';
type = {'AA', 'BB', 'CC', 'BB', 'BB', 'BB', 'AA', 'CC', 'CC'}.';
t = table(year, type);
>> unique(t,'rows')
ans =
6×2 table
year type
____ ____
1994 'AA'
1994 'BB'
1994 'CC'
1995 'BB'
1996 'AA'
1996 'CC'
>>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by