Cobine two cell arrays with Nested Cellfun

조회 수: 5 (최근 30일)
Moiz
Moiz 2016년 2월 10일
댓글: Moiz 2016년 2월 10일
Hi all,
I have two cell arrays : A = {'13','15','17,'18'}; B = {'16','18','20','22','24',25','26','27,'28'};
I want to comine them and create a new cell array (of size 1x36) such that each element in the cell array is of the form '13x16','13x18',....'13x28','15x16',....'15x28',...'18x16',....'18x28'
I thought of using a nested cellfun for this like shown below : Combi = cellfun(@(x) cellfun(@(y) [x, 'x', y],B,'Uniform',false), A,'Unifrom',false);
However I get an error saying 'Input #3 expected to be a cell array, was char instead'
Any ideas what could be going on ?

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 2월 10일
[b,a] = ndgrid(B,A);
out = strcat(a,{'x'},b);
  댓글 수: 1
Moiz
Moiz 2016년 2월 10일
Tried this but does not seem to work. First of all the ndgrid function returns an error 'Undefined function 'full' for input arguments of type 'cell'...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by