Info
This question is closed. Reopen it to edit or answer.
Combination of 2 numbers in 7 rows
1 view (last 30 days)
Show older comments
Hi!
I need to get all possible combinations of 1 and 0 in 7 rows, 128 different combinations. How can i get this in Matlab? I currently uisng Matlab 7.6.0
0 Comments
Answers (2)
Jan
on 29 Nov 2011
DEC2BIN converts the doubles to chars, and the -'0' converts them back to doubles. Directly:
out = rem(floor((0:127)' * pow2(-6:0)), 2)
0 Comments
Daniel Shub
on 29 Nov 2011
dec2bin(0:127)
Building on the comments I am going to edit my answer. The above command produces 128 rows of 7 element strings. Specifically it is a 128x7 matrix of class char. That was my interpretation of what you wanted. Andrei and Walter think you want a 128x7 matrix of class double. You can get this with
dec2bin(0:127)-'0'
You also might want a 128x7 matrix of class logical
logical(dec2bin(0:127)-'0')
3 Comments
Daniel Shub
on 29 Nov 2011
@Andrei and Walter, I wonder want Per wants (char or double), although I think logical is probably better than double. If you put them as an answer, maybe we will find out.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!