MATLAB: How to unstack/transpose table in Matlab

MATLAB Computational Finance Suitetransposeunstack

I need to unstack/transpose a table but couldn''t do using unstack ot transpose functions. Please see attached file.

Best Answer

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'