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

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 6일
편집: KALYAN ACHARJYA 2020년 12월 6일
What you have tried so far?
dec2bin(1:15)
Using for loop, please share your efforts?
safwan shraideh
safwan shraideh 2020년 12월 6일
Ok Kalyan, but this is not matrix, this is char. Can you help me again?

댓글을 달려면 로그인하십시오.

답변 (3개)

Bruno Luong
Bruno Luong 2020년 12월 6일
편집: Bruno Luong 2020년 12월 6일

2 개 추천

>> 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
Setsuna Yuuki.
Setsuna Yuuki. 2020년 12월 6일

0 개 추천

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

Stephen23
Stephen23 2020년 12월 6일
편집: Stephen23 2020년 12월 6일
Exactly as its author states, this is "not very efficient".
Or in one word, it is very inefficient. Best avoided.
Setsuna Yuuki.
Setsuna Yuuki. 2020년 12월 6일
I confirm, best avoided :D
Bruno Luong
Bruno Luong 2020년 12월 6일
I have impression Bastian wants to make us a joke.
safwan shraideh
safwan shraideh 2020년 12월 7일
It is not efficient, but thanks for your effort Bastian.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2020년 12월 6일

댓글:

2020년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by