How do I create a matrix with all binary combinations?
99 次查看(过去 30 天)
显示 更早的评论
Hi
I want to create a matrix with all binary combinations. If N is the length of the binary code, there would be possible combinations. Below are , and the 16 possible binary combinations are displayed.
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
How can I create such a matrix automatically? I don't really care which order they are in, as long as every combination is present, and N is a variable.
Thanks in advance.
0 个评论
采纳的回答
更多回答(2 个)
James Tursa
2020-5-13
编辑:James Tursa
2020-5-13
dec2bin(0:2^N-1) - '0'
Note that this is only practical for relatively small values of N. Even moderatly large N can cause this to exceed your available memory.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!