How to Compute All Combinations of Vectors of Length 6 Made up of Numbers -1 and 1?

1 回表示 (過去 30 日間)
Dario Miric
Dario Miric 2022 年 1 月 28 日
編集済み: Dario Miric 2022 年 1 月 28 日
For example, If I have two numbers [-1 1] in a some random order in a vector of length 6, how can I compute all 64 combinations of these numbers such that a result is a matrix of 64x6 dimension?
To make my question more clear, result would look something like this:
A = [-1 1 -1 1 -1 1; 1 -1 1 1 -1 -1 1; -1 1 -1 -1 1 -1; 1 -1 -1 1 -1 -1; etc.]
with all 64 possible combinations. Since there are 64 combinations, a resulting matrix needs to have 64 rows and 6 columns since every row (vector) has 6 numbers.
  2 件のコメント
Torsten
Torsten 2022 年 1 月 28 日
Only 15, not 64 combinations.
Dario Miric
Dario Miric 2022 年 1 月 28 日
編集済み: Dario Miric 2022 年 1 月 28 日
Yes, since I only have two different values, I will have a lot of equal combinations (64 - 15 = 49). Do you know if there is a function to do this?

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

採用された回答

Torsten
Torsten 2022 年 1 月 28 日
Brute force would be
unique(perms(A))
Maybe there is a better solution.
  5 件のコメント
Torsten
Torsten 2022 年 1 月 28 日
If you have a fixed vector v made up of -1 and 1 and you want to get all combinations of the elements of this vector, you get 6! permutations where many of them will repeat.
If you want all possible vectors of length 6 made up of the numbers -1 and 1, you get 64 such vectors.
I think the last thing is what you want, and permn will do this for you.
Dario Miric
Dario Miric 2022 年 1 月 28 日
Exactly! Thank you.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by