Creating a matrix of all possible combinations given multiple vectors
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Walter Roberson
on 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.
More Answers (1)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!