Reputation: 4336
I have two cells,
A =
[100x2 double] [80x2 double] [50x2 double]
B =
[100x5 double] [80x5 double] [50x5 double]
How can I Concatenate them to get something like C = cat(2,A,B)
for each array. C
must be,
C =
[100x7 double] [80x7 double] [50x7 double]
Thanks,
Upvotes: 2
Views: 118
Reputation: 29064
C = cellfun(@(a, b) [a b], A, B, 'UniformOutput', false);
This will create the cell array C for you.
Example:
>> A = { zeros(100,2), zeros(200,2) };
>> B = { ones(100,5), ones(200,5)};
>> C = cellfun(@(a, b) [a b], A, B, 'UniformOutput', false);
Upvotes: 3
Reputation: 112679
You probably need some kind of loop:
C = arrayfun(@(n) [A{:,n} B{:,n}], 1:numel(A), 'uniformoutput', 0);
Of course, if the number of cells in A
(and B
) is fixed, you can replace the loop by an enumeration:
C = {[A{:,1} B{:,1}] [A{:,2} B{:,2}] [A{:,3} B{:,3}]};
Upvotes: 1