フィルターのクリア

Creating a matrix of all possible combinations given multiple vectors

3 ビュー (過去 30 日間)
Nate F
Nate F 2021 年 1 月 12 日
コメント済み: Nate F 2021 年 1 月 13 日
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?

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 12 日
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.
  1 件のコメント
Nate F
Nate F 2021 年 1 月 13 日
Thanks a lot Walter, this does exactly what I need!!!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2021 年 1 月 12 日
REad about perms and nchoosek.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by