Take cartesian product between lists of tuples and a vector
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
mrule
am 30 Jan. 2015
Kommentiert: Mike Croucher
am 4 Apr. 2023
I know matlab doesn't have tuples or vectors, but what I mean is say I have
A = [ 0 1 ; 2 3 ]
B = [ 4 5 ; 6 7 ]
C = [ 0 1 ]
I'd like to take the cartesian product of these items, like the "product" function from itertools in python.
product(A,B,C) =
[ 0 1 4 5 0;
0 1 4 5 1;
0 1 6 7 0;
0 1 6 7 1;
2 3 4 5 0;
2 3 4 5 1;
2 3 6 7 0;
2 3 6 7 1]
Is there a function in matlab that does this, accepting an arbitrary number of arguments? All the examples say "use meshgrid" which doesn't work in this case since that only takes the product of 2 or 3 vectors.
1 Kommentar
Mike Croucher
am 4 Apr. 2023
Use the combinations function. New in R2023a The new combinations function in MATLAB – for cartesian products and parameter sweeps » The MATLAB Blog - MATLAB & Simulink (mathworks.com)
Akzeptierte Antwort
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!