how to write special matrices

4 views (last 30 days)
safwan shraideh
safwan shraideh on 6 Dec 2020
Commented: safwan shraideh on 7 Dec 2020
how can I write this matrix
a=[0 0 0 0;
0 0 0 1;
0 0 1 0;
0 0 1 1;
0 1 0 0;
0 1 0 1;
0 1 1 0;
0 1 1 1;
1 0 0 0;
1 0 0 1;
1 0 1 0;
1 0 1 1;
1 1 0 0;
1 1 0 1;
1 1 1 0;
1 1 1 1;]
using for loop?
  2 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 6 Dec 2020
Edited: KALYAN ACHARJYA on 6 Dec 2020
What you have tried so far?
dec2bin(1:15)
Using for loop, please share your efforts?
safwan shraideh
safwan shraideh on 6 Dec 2020
Ok Kalyan, but this is not matrix, this is char. Can you help me again?

Sign in to comment.

Answers (3)

Bruno Luong
Bruno Luong on 6 Dec 2020
Edited: Bruno Luong on 6 Dec 2020
>> dec2bin(0:2^4-1)-'0'
ans =
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1

Walter Roberson
Walter Roberson on 6 Dec 2020

Setsuna Yuuki.
Setsuna Yuuki. on 6 Dec 2020
I think it is not very efficient, but works
a = dec2bin(0:15);
i = 1;
while i<17
c = randi([0 1],1,4);
if(a(i,1:4) == sprintf('%g',c))
b(i,1:4) = c;
i = i+1;
end
end
b =
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
  4 Comments
Bruno Luong
Bruno Luong on 6 Dec 2020
I have impression Bastian wants to make us a joke.
safwan shraideh
safwan shraideh on 7 Dec 2020
It is not efficient, but thanks for your effort Bastian.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!