Concatenate cells

纵然是瞬间 提交于 2019-12-01 23:57:21
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);

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}]};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!