フィルターのクリア

How to exhaust all the binary array of length N?

1 回表示 (過去 30 日間)
Lee
Lee 2023 年 4 月 22 日
回答済み: Walter Roberson 2023 年 4 月 22 日
Hi everyone! I hope to do the following thing.
For an array of N components and each component can only take 1 or 0, I hope to exhaust all the possible assignment of the array.
Specifically I want to get a matrix with 2^N rows and N columns with each row corresponding to a possible case. How should I do this? Is there a MATLAB built-in function to do this?

採用された回答

Walter Roberson
Walter Roberson 2023 年 4 月 22 日
N = 5;
desired_matrix = dec2bin(0:2^N-1) - '0'
desired_matrix = 32×5
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by