필터 지우기
필터 지우기

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개)

KSSV
KSSV 2021년 1월 12일
REad about perms and nchoosek.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by