说我有几个具有相同变量和相同大小的表。当每个结构包含来自不同表的多个变量时,如何将它们组合在一起以形成结构表?
%input
a = table([1; 1], [2; 2]);
b = table(['c'; 'c'], ['d'; 'd']);
%output
ab = table([struct('a', 1, 'b', 'c'); struct('a', 1, 'b', 'c')], ...
[struct('a', 2, 'b', 'd'); struct('a', 2, 'b', 'd')]);
我正在寻找一种优雅的方式,而不是冗长的代码。
答案 0 :(得分:3)
我个人将使用嵌套的table
(而不是struct
中的table
),并使用inner2outer
,如下所示:
>> inner2outer(table(a,b))
ans =
2×2 table
Var1 Var2
a b a b
______ ______
1 c 2 d
1 c 2 d