How do I unstack/transpose table in Matlab?
15 次查看(过去 30 天)
显示 更早的评论
I need to unstack/transpose a table but couldn''t do using unstack ot transpose functions. Please see attached file.
2 个评论
dpb
2019-7-31
So show us what you tried and what happened...showing an expected output would help I have no idea what you would want that to be.
采纳的回答
TADA
2019-7-31
unstack groups using a third column, but you can trick it to do what you want by adding a fake third column
id={'id1';'id1';'id2';'id2';'id2'};
cn={'c1';'c2';'c1';'c2';'c3'};
t=table(id,cn,cn,'VariableNames', {'id', 'cn', 'cn_'});
%unstack/transpose
t1=unstack(t,'cn_','cn');
t1 =
2×4 table
id c1 c2 c3
_____ ____ ____ ____
'id1' 'c1' 'c2' ''
'id2' 'c1' 'c2' 'c3'
4 个评论
stone_ward
2020-2-21
How were you able to do this without defining an aggregation function? I've been trying to use unstack on my table of non-numeric data, which is similar to the example, except that I do happen to have 3 columns of data. Everytime I try to use it, I get an error about needing and aggregation function. When I supply one, I get the error "AGGREGATIONFUNCTION must return a value whose size conforms to elements of hte data variable 'Data'."
Note: Data is my datavar.
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!