how to write special matrices

1 回表示 (過去 30 日間)
safwan shraideh
safwan shraideh 2020 年 12 月 6 日
コメント済み: safwan shraideh 2020 年 12 月 7 日
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 日
>> 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 件のコメント
safwan shraideh
safwan shraideh 2020 年 12 月 7 日
Thank you Bruno.

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


Walter Roberson
Walter Roberson 2020 年 12 月 6 日
  1 件のコメント
safwan shraideh
safwan shraideh 2020 年 12 月 7 日
Thanks Walter.

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


Setsuna Yuuki.
Setsuna Yuuki. 2020 年 12 月 6 日
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 件のコメント
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.

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by