how to write special matrices

5 vues (au cours des 30 derniers jours)
safwan shraideh
safwan shraideh le 6 Déc 2020
Commenté : safwan shraideh le 7 Déc 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 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 6 Déc 2020
Modifié(e) : KALYAN ACHARJYA le 6 Déc 2020
What you have tried so far?
dec2bin(1:15)
Using for loop, please share your efforts?
safwan shraideh
safwan shraideh le 6 Déc 2020
Ok Kalyan, but this is not matrix, this is char. Can you help me again?

Connectez-vous pour commenter.

Réponses (3)

Bruno Luong
Bruno Luong le 6 Déc 2020
Modifié(e) : Bruno Luong le 6 Déc 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 commentaire
safwan shraideh
safwan shraideh le 7 Déc 2020
Thank you Bruno.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 6 Déc 2020
  1 commentaire
safwan shraideh
safwan shraideh le 7 Déc 2020
Thanks Walter.

Connectez-vous pour commenter.


Setsuna Yuuki.
Setsuna Yuuki. le 6 Déc 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 commentaires
Bruno Luong
Bruno Luong le 6 Déc 2020
I have impression Bastian wants to make us a joke.
safwan shraideh
safwan shraideh le 7 Déc 2020
It is not efficient, but thanks for your effort Bastian.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by