MATLAB Answers

how can I creat a matrix of all possible combinations of zero and ones across eight digits.

8 views (last 30 days)
Yonatan Vanunu
Yonatan Vanunu on 18 Dec 2019
Answered: David Goodmanson on 20 Dec 2019
Hey I am trying to create a matrix of all possible combinations of zeros and ones across eight digits sequence. I know the number of combinations should be 2^8 = 256.
A simple example for all combinations of 3 digit sequence will be
1 0 0
1 1 0
1 1 1
0 1 0
0 1 1
0 0 1
1 0 1
0 0 0
Is there a way to create a matrix for eight digit sequence?
Thanks!

  1 Comment

Sign in to comment.

Answers (3)


Ridwan Alam
Ridwan Alam on 18 Dec 2019
decimalVector= [0:1:(2^8)-1]';
binaryMatrix = de2bi(decimalVector);

  0 Comments

Sign in to comment.


David Goodmanson
David Goodmanson on 20 Dec 2019
HI Yonatan,
not a black box:
function a = x10(ndigits)
a = ['0';'1'];
count = 1;
while count < ndigits
n = size(a,1);
zers = repmat('0',n,1);
ons = repmat('1',n,1);
a = [zers a; ons a];
count = count+1;
end
end

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by