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

3 views (last 30 days)
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?

Accepted Answer

Stephen23
Stephen23 on 7 Sep 2018
Edited: Stephen23 on 23 Feb 2022

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!