Get all unique combinations of 2 columns from a table
Show older comments
I have a table that has 4 variables, similar to this:
Item1 Item2 Item3 Item4
_____ _____ _____ _____
1 5 7 10
What is the best way to produce the delta of each combination of columns? Ex. Item1 vs Item2, Item1 vs Item3, etc.
Accepted Answer
More Answers (1)
Cris LaPierre
on 19 Jan 2022
0 votes
3 Comments
I was probably trying too hard to make use of the variablenames. Stephen's approach is simpler by using column numbers instead.
T = table(1, 5, 7 ,10, 'VariableNames', {'Item1' 'Item2' 'Item3' 'Item4'});
C = nchoosek(T.Properties.VariableNames,2)
delta = diff([T{1,{C{:,1}}};T{1,{C{:,2}}}])
Austin B
on 19 Jan 2022
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!