enumerate all possible combinations of an input space

조회 수: 4 (최근 30일)
xi
xi 2021년 3월 14일
답변: Walter Roberson 2021년 3월 14일
for example I have 3 categorical variable, X1 can be 'A,B,or C', X2 can be 'A or D', X3 can be 'E or F', so there can be 3X2X2 different possible combinations:
AAE,AAF, ADE,ADF,BAE,BAF,BDE,BDF,CAE,CAF,CDE,CDF.
which function sould I use to create such a complete list?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 14일
X1 = categorical({'A', 'B', 'C'})
X1 = 1×3 categorical array
A B C
X2 = categorical({'A', 'D'})
X2 = 1×2 categorical array
A D
X3 = categorical({'E', 'F'})
X3 = 1×2 categorical array
E F
[X1g, X2g, X3g] = ndgrid(X1, X2, X3);
output = [X1g(:), X2g(:), X3g(:)]
output = 12×3 categorical array
A A E B A E C A E A D E B D E C D E A A F B A F C A F A D F B D F C D F

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by