フィルターのクリア

Possible combinations for elements of five vectors

2 ビュー (過去 30 日間)
manish sharma
manish sharma 2015 年 7 月 9 日
コメント済み: manish sharma 2015 年 7 月 9 日
Hello,
I am stuck with a question involving combinations (and permutations, may be!). I would really appreciate any help.
----------------------------
I have five vectors:
D1=[a1 a2 a3]
D2=[b1 b2 b3]
...
D5=[e1 e2 e3]
where a1, a2, a3, b1, b2, b3, ....e1, e2, e3 are all positive integers
I am interested in getting all the possible combinations such that only one number is chosen from each vector. Each generated combination should therefore have 5 elements. For example:
[a1, b1, c1, d1, e1]
[a1, b2, c1, d1, e1]
...
etc.
----------------------------
  • No need to mention but there shouldn't be any combination with size less or more than 5. And, just one element should be chosen from each vector. For example, [a1, b1, b2, c1, d1] shall not be in the solution since D2's elements are chosen twice and there ain't any chosen from D5.
I hope I was good enough with the words.
Thanks!

採用された回答

James Tursa
James Tursa 2015 年 7 月 9 日
編集済み: James Tursa 2015 年 7 月 9 日
allcomb(D1,D2,D3,D4,D5)
or
allcomb(D1,D2,D3,D4,D5,'matlab')
Depending on which indexing order you want. You can find allcomb by Jos here:
  1 件のコメント
manish sharma
manish sharma 2015 年 7 月 9 日
You're a life saver, James! This was clear, concise, and perfect.
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by