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 3y = 4 5y = 6x1 = 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?
Best Answer