如何在没有for循环的情况下将单元格数组的元素插入到另一个单元格数组中?
单元格A
的元素都是整数。
输入:
A = [1x2 double] [1x2 double]
[1x2 double] [1x2 double]
[1x2 double] [1x2 double]
[1x2 double] [1x2 double]
[1x2 double] [1x2 double]
[1x2 double] [1x2 double]
A{1}=[2 5]
A{2}=[6 8]
B=[8] [7]
[7] [0]
[4] [3]
[7] [0]
[2] [1]
[1] [2]
C=cell(6,2);
输出:
C{1}=[A{1} B{1}];
C{2}=[A{2} B{2}];
答案 0 :(得分:1)
cellfun
的一些经典用法可能
C=cellfun(@horzcat, A, B, 'uni', 0)
答案 1 :(得分:0)
可能吗:
B = reshape(B, [], 1);
C = [A(:) B(1:length(A))];