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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Stephen23
Stephen23 am 7 Sep. 2018
Bearbeitet: Stephen23 am 23 Feb. 2022

Weitere Antworten (0)

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by