How to change table dimensions by ordering by column values?
Show older comments
Here is my table so far:
1 -1 0.532
1 -2 0.765
1 0 0.726
1 1 0.526
1 2 0.915
2 -1 0.693
2 -2 0.485
2 0 0.624
2 1 0.627
2 2 1.197
3 -1 0.647
3 -2 0.850
3 0 0.723
3 1 0.516
3 2 0.706
How can I change it into a format that looks like this:
-1 -2 0 1 2
1
2
3
Accepted Answer
More Answers (1)
Peter Perkins
on 4 Jun 2018
Not clear how you need to use your result, but this is exactly what unstack does:
t =
15×3 table
Var1 Var2 Var3
____ ____ _____
1 -1 0.532
1 -2 0.765
1 0 0.726
1 1 0.526
1 2 0.915
2 -1 0.693
2 -2 0.485
2 0 0.624
2 1 0.627
2 2 1.197
3 -1 0.647
3 -2 0.85
3 0 0.723
3 1 0.516
3 2 0.706
>> t2 = unstack(t,'Var3','Var2','GroupingVariable','Var1');
Warning: Variable names were modified to make them valid MATLAB identifiers.
>> t2.Var1 = [];
>> t2.Properties.RowNames = {'One' 'Two' 'Three'};
>> t2.Properties.VariableNames = {'MinusTwo' 'MinusOne' 'Zero' 'One' 'Two'}
t2 =
3×5 table
MinusTwo MinusOne Zero One Two
________ ________ _____ _____ _____
One 0.765 0.532 0.726 0.526 0.915
Two 0.485 0.693 0.624 0.627 1.197
Three 0.85 0.647 0.723 0.516 0.706
Categories
Find more on Tables 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!