MATLAB Table - Unique lookup from multiple instances

1 view (last 30 days)
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!

Accepted Answer

Voss
Voss on 27 May 2022
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

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!