Combination of 2 numbers in 7 rows
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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
Respuestas (2)
Jan
el 29 de Nov. de 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)
Daniel Shub
el 29 de Nov. de 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 comentarios
Andrei Bobrov
el 29 de Nov. de 2011
dec2bin(0:127)+'0'-96
Walter Roberson
el 29 de Nov. de 2011
dec2bin(0:127)-'0'
Daniel Shub
el 29 de Nov. de 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.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!