how to write special matrices
Mostra commenti meno recenti
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 Commenti
KALYAN ACHARJYA
il 6 Dic 2020
Modificato: KALYAN ACHARJYA
il 6 Dic 2020
What you have tried so far?
dec2bin(1:15)
Using for loop, please share your efforts?
safwan shraideh
il 6 Dic 2020
Risposte (3)
Bruno Luong
il 6 Dic 2020
Modificato: Bruno Luong
il 6 Dic 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
1 Commento
safwan shraideh
il 7 Dic 2020
Walter Roberson
il 6 Dic 2020
1 voto
You can use the "odometer" code pattern.
1 Commento
safwan shraideh
il 7 Dic 2020
Setsuna Yuuki.
il 6 Dic 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 Commenti
Setsuna Yuuki.
il 6 Dic 2020
I confirm, best avoided :D
Bruno Luong
il 6 Dic 2020
I have impression Bastian wants to make us a joke.
safwan shraideh
il 7 Dic 2020
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!