连接单元格

时间:2014-10-18 17:05:13

标签: arrays matlab matrix cell

我有两个细胞,

A =
 [100x2 double]    [80x2 double]    [50x2 double]
B =
 [100x5 double]    [80x5 double]    [50x5 double]

如何连接它们以获得每个数组C = cat(2,A,B)之类的内容。 C必须是,

C =
 [100x7 double]    [80x7 double]    [50x7 double]

谢谢,

2 个答案:

答案 0 :(得分:3)

C = cellfun(@(a, b) [a b], A, B, 'UniformOutput', false);

这将为您创建单元格数组C.​​

示例:

>> A = { zeros(100,2), zeros(200,2) };
>> B = { ones(100,5), ones(200,5)};
>> C = cellfun(@(a, b) [a b], A, B, 'UniformOutput', false);

答案 1 :(得分:1)

您可能需要某种循环:

C = arrayfun(@(n) [A{:,n} B{:,n}], 1:numel(A), 'uniformoutput', 0);

当然,如果A(和B)中的单元格数是固定的,则可以用枚举替换循环:

C = {[A{:,1} B{:,1}] [A{:,2} B{:,2}] [A{:,3} B{:,3}]};