我有一个表名output
,其中包含这样的维度:
cat values s1 s2 sub_cat
1 [1x2 double] 0.66584 3.1383 {2x1 cell}
值如下:
cat values s1 s2 sub_cat
1 2.5 3.4 0.555 3.999 emozi-1
emozi-3
2 2.9 7.1 5.0 2 khazal-11
kha-9
如何重新安排此表格(将矢量移至正常状态):
cat values s1 s2 sub-cat
1 2.5 0.555 3.999 emozi-1
1 3.4 0.555 3.999 emozi-3
2 2.9 5.0 2 khazal-11
2 7.1 5.0 2 kha-9
任何人都可以帮助在matlab中做到这一点吗?
答案 0 :(得分:0)
我认为之后的表stack
操作。这有点棘手,因为我认为你试图同时堆叠两个表变量(没有得到所有的组合),所以这就是我认为你需要的:
%# Sample table data
t = table([1;2], [1, 2; 3, 4], [0.1; 0.2], {'a', 'b'; 'c', 'd'}, ...
'VariableNames', {'cat', 'values', 's1', 'sub_cat'});
%# Combine corresponding columns of 'values' and 'sub_cat' so
%# that we've got something we can stack
t2 = table(t.cat, [num2cell(t.values(:,1)), t.sub_cat(:,1)], ...
[num2cell(t.values(:,2)), t.sub_cat(:,2)], ...
t.s1, 'VariableNames', {'cat', 'vs1', 'vs2', 's1'});
%# Actually call 'stack'
t3 = stack(t2, {'vs1', 'vs2'});
%# Unpick the variables in 't3' into something more useful
t4 = table(t3.cat, t3.s1, cell2mat(t3.vs1_vs2(:,1)), ...
t3.vs1_vs2(:,2), 'VariableNames', ...
{'cat', 's1', 'values', 'sub_cat'})