How to create all combinations of boolean vector possibilities?
18 ビュー (過去 30 日間)
古いコメントを表示
Some background for the problem - I have 5 situations that can happen independently of the other situations. I want to create a matrix with rows that look like [1 0 0 0 0] , [1 1 0 0 0], etc. where the rows will be 2^5-1 since the vector [0 0 0 0 0] doesn't matter. The boolean logic 1 means that the situation has occured, 0 means the situation has not occured. Is there a way to easily create this matrix? Please let me know if any further clarification is needed. Thank you for the help!
0 件のコメント
採用された回答
David Hill
2022 年 2 月 8 日
編集済み: David Hill
2022 年 2 月 8 日
x=1:2^5-1;
m=logical(dec2bin(x',5)-'0');
1 件のコメント
Steven Lord
2022 年 2 月 8 日
Instead of explicitly calling logical you could use the == operator.
x = 1:2^5-1;
m = dec2bin(x', 5) == '1'
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!