combinations
説明
例
ベクトルの組み合わせ
2 つのベクトルのすべての要素の組み合わせを生成します。出力 table T
の各行は、最初のベクトルからの最初の要素と 2 番目のベクトルからの 2 番目の要素の組み合わせです。変数 Var1
には最初のベクトルからの要素が含まれ、変数 Var2
には 2 番目のベクトルからの要素が含まれます。
T = combinations([1 8 6],[9 3 2])
T=9×2 table
Var1 Var2
____ ____
1 9
1 3
1 2
8 9
8 3
8 2
6 9
6 3
6 2
配列の組み合わせ
2 つの配列のすべての要素の組み合わせを生成します。関数 combinations
は、要素の組み合わせを生成する前に各入力を列ベクトルに変更します。
T = combinations([7 3;2 6],[9 1 4])
T=12×2 table
Var1 Var2
____ ____
7 9
7 1
7 4
2 9
2 1
2 4
3 9
3 1
3 4
6 9
6 1
6 4
string 配列の組み合わせ
3 つの string 配列のすべての要素の組み合わせを生成します。出力 table の変数の名前は string 配列の名前に基づきます。
ID = ["A" "B" "C"]; color = ["red" "blue" "green"]; sz = ["small" "large"]; T = combinations(ID,color,sz)
T=18×3 table
ID color sz
___ _______ _______
"A" "red" "small"
"A" "red" "large"
"A" "blue" "small"
"A" "blue" "large"
"A" "green" "small"
"A" "green" "large"
"B" "red" "small"
"B" "red" "large"
"B" "blue" "small"
"B" "blue" "large"
"B" "green" "small"
"B" "green" "large"
"C" "red" "small"
"C" "red" "large"
"C" "blue" "small"
"C" "blue" "large"
⋮
各組み合わせ全体で要素を組み合わせてデータ ラベルを作成します。中かっこ {} を使用して table T
の内容を抽出し、join
を使用して行全体で要素を組み合わせます。
labels = join(T{:,:},"_")
labels = 18x1 string
"A_red_small"
"A_red_large"
"A_blue_small"
"A_blue_large"
"A_green_small"
"A_green_large"
"B_red_small"
"B_red_large"
"B_blue_small"
"B_blue_large"
"B_green_small"
"B_green_large"
"C_red_small"
"C_red_large"
"C_blue_small"
"C_blue_large"
"C_green_small"
"C_green_large"
さまざまなデータ型の入力
さまざまなサイズとデータ型の入力のすべての要素の組み合わせを生成します。
出力 table T
の行数は、numel(A1)
、numel(A2)
、および numel(A3)
の積と等しくなります。出力 table T
内の各変数のデータ型は、対応する入力のデータ型と同じです。
A1 = [0 1; 2 3]; A2 = ["a" "b" "c"]; A3 = categorical(["x" "y"]); T = combinations(A1,A2,A3)
T=24×3 table
A1 A2 A3
__ ___ __
0 "a" x
0 "a" y
0 "b" x
0 "b" y
0 "c" x
0 "c" y
2 "a" x
2 "a" y
2 "b" x
2 "b" y
2 "c" x
2 "c" y
1 "a" x
1 "a" y
1 "b" x
1 "b" y
⋮
入力引数
A1,...,An
— 入力配列 (個別の引数として)
スカラー | ベクトル | 行列 | 多次元配列
入力配列。スカラー、ベクトル、行列または多次元配列のコンマ区切りリストとして指定します。入力配列ごとにサイズやデータ型が異なっていてもかまいません。
データ型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| string
| struct
| datetime
| duration
| calendarDuration
| categorical
| cell
複素数のサポート: あり
バージョン履歴
R2023a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)