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

6 ビュー (過去 30 日間)
Yonatan Vanunu
Yonatan Vanunu 2019 年 12 月 18 日
回答済み: David Goodmanson 2019 年 12 月 20 日
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 件のコメント
Ridwan Alam
Ridwan Alam 2019 年 12 月 20 日
Hi Yonatan, does the response below work for you? If yes, please accept as an answer.

サインインしてコメントする。

回答 (3 件)

Stephen23
Stephen23 2019 年 12 月 18 日
>> dec2bin(0:7) % try 0:255
ans =
000
001
010
011
100
101
110
111

Ridwan Alam
Ridwan Alam 2019 年 12 月 18 日
decimalVector= [0:1:(2^8)-1]';
binaryMatrix = de2bi(decimalVector);

David Goodmanson
David Goodmanson 2019 年 12 月 20 日
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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by