MATLAB Table - Unique lookup from multiple instances

Hi all
I have a Table. In column 1 there are multiple instances of some double (an "ID"). Each of these IDs is uniquely paired with another number in column 2. I want to collapse this Table in to just one ID in column 1, paired with its match from column 2.
so for example:
TABLE1
col1 col2
a 3
a 3
a 3
b 9
b 9
c 27
c 27
RESULT: TABLE2
col1 col2
a 3
b 9
c 27
any help is much appreciated! thank you!

 채택된 답변

Voss
Voss 2022년 5월 27일
TABLE1 = table( ...
{'a';'a';'a';'b';'b';'c';'c'}, ...
[3;3;3;9;9;27;27], ...
'VariableNames',{'col1' 'col2'})
TABLE1 = 7×2 table
col1 col2 _____ ____ {'a'} 3 {'a'} 3 {'a'} 3 {'b'} 9 {'b'} 9 {'c'} 27 {'c'} 27
TABLE2 = unique(TABLE1) % or unique(TABLE1,'rows')
TABLE2 = 3×2 table
col1 col2 _____ ____ {'a'} 3 {'b'} 9 {'c'} 27

댓글 수: 2

wonderful - thank you!
Voss
Voss 2022년 6월 1일
편집: Voss 2022년 6월 1일
You're welcome!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

2022년 5월 27일

편집:

2022년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by