Filter löschen
Filter löschen

Creating a matrix of all possible combinations given multiple vectors

3 Ansichten (letzte 30 Tage)
As the title says if you are given various vectors with variable length for example:
x1 = [0 1];
x2 = [100 200 300];
x3 = [Inf Inf];
x4 = [1e-2 1e-6 1e-10];
x5 = 4;
x6 = [1 2 3];
In this case there are 6 inputs giving 108 combinations. Is there a slick way to create a 108x6 matrix without using embedded for loops? I am asking to not use for loops because I would like to dynamically change the amount of inputs without having to hard code the loops. I've been trying but I can't seem to find a solution. Does anyone have some ideas?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Jan. 2021
See https://www.mathworks.com/matlabcentral/answers/623358-get-a-combination-of-unique-paths-for-given-pair-of-numbers#comment_1082638 for code for this purpose. It was specifically designed to permit different numbers of enteries in each slot, and to permit non-consecutive entries, and to permit the entries to have different data types.

Weitere Antworten (1)

KSSV
KSSV am 12 Jan. 2021
REad about perms and nchoosek.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by