Azzera filtri
Azzera filtri

Creating a matrix of all possible combinations given multiple vectors

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 12 Gen 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.

Più risposte (1)

KSSV
KSSV il 12 Gen 2021
REad about perms and nchoosek.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by