Create a matrix of binary numbers generated by sequence
Mostrar comentarios más antiguos
I want to create a general matrix to create outputs of the below format...
if n=1
output=[1 0]
if n=2
output=[1 1
1 0
0 1
0 0]
if n=3
output=[1 1 1
1 1 0
1 0 1
1 0 0
0 1 1
0 1 0
0 0 1
0 0 0]
for any number of n; the output matrix will be of the order of [2^n X n]
Respuesta aceptada
Más respuestas (2)
Azzi Abdelmalek
el 30 de Mzo. de 2014
Editada: Azzi Abdelmalek
el 30 de Mzo. de 2014
n=3;
s=0:1;
idx=rem(nchoosek(0:2^n-1,n),2)+1;
out=flipud(unique(s(idx),'rows'))
1 comentario
Mohammed
el 30 de Mzo. de 2014
görkem tatar
el 18 de Jun. de 2021
0 votos
y =dec2bin(x)
x = 'dec variable'
y = 'convertion of the dec variable to bin'
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!