If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

3 ビュー (過去 30 日間)
If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

採用された回答

Guillaume
Guillaume 2017 年 5 月 31 日
Most likely there's already an implementation on the FileExchange. Otherwise, it's easy to implement:
elements = [1 2 3];
count = 6;
combs = cell(1, count);
[combs{:}] = ndgrid(elements);
combs = reshape(cat(count + 1, combs{:}), [], count)

その他の回答 (1 件)

ES
ES 2017 年 5 月 31 日
perms
example:
perms(repmat([1 2 3], 1,2))
  1 件のコメント
Guillaume
Guillaume 2017 年 5 月 31 日
I'm fairly certain that's not what is asked, if only for the fact that this does not generate 3^6 entries.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by