How to automatically split a matrix into multi-Vectors of n variables for combination?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
cui,xingxing
am 7 Sep. 2018
Bearbeitet: Stephen23
am 23 Feb. 2022
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?
2 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!