## How to automatically split a matrix into multi-Vectors of n variables for combination?

### cui (view profile)

on 7 Sep 2018
Latest activity Commented on by cui

on 7 Sep 2018

### Stephen Cobeldick (view profile)

Hi, I use the Matlab built-in function "combvec" to Create all combinations of vectors.But the number of input variables is uncertain. For example：supporse my T is [{[1,2,3]},{[4,5]},{6}],a cell array，has three vectors,which each element inside is a vector;
T = [{[1,2,3]},{[4,5]},{6}];
y = cellfun(@getEle,T,'UniformOutput',false);
x1 = combvec(y)
x2 = combvec(T{1},T{2},T{3})
Result:
y =
1
2
3
y =
4
5
y =
6
x1 =
1×3 cell 数组
{3×1 double} {2×1 double} {[6]}
x2 =
1 2 3 1 2 3
4 4 4 5 5 5
6 6 6 6 6 6
the getEle function is:
function y = getEle(x)
y = x(:)
I want to get n variables ,so i design "getEle" and cellfun functions,but x1 is not my want result.
X2 is the result I want.But the cell array T is usually not fixed in size(n vectors,n is not fixed), and each element stores a vector of different size. Now the question is how to pass each vector of T into the combvec function?

Walter Roberson

on 7 Sep 2018
What is getEle ?
cui

### cui (view profile)

on 7 Sep 2018
oh, getEle is here:
function y = getEle(x)
y = x(:)

R2018a

on 7 Sep 2018