フィルターのクリア

How to generate a binary matrix with unique rows (or) columns?

1 回表示 (過去 30 日間)
Nitin SHrinivas
Nitin SHrinivas 2021 年 8 月 1 日
編集済み: Matt J 2021 年 8 月 1 日
n = 15; k = 10;
flag = 0;
for l=1:2^k
while(1)
temp = randi([0,1] , 1,n);
for m=1:l-1
if(codeword(m,:) == temp)
flag = 1;
end
end
if(flag ==0)
break;
end
end
codeword(l,:) = temp;
end
This is a very time complex code!!
Can anyone suggest any other way with which I can solve this problem?
Thanks.
  1 件のコメント
Jonas
Jonas 2021 年 8 月 1 日
編集済み: Jonas 2021 年 8 月 1 日

i suggest you just write ascending numbers in binary format, then all rows or columns are unique. think about how many rows and digits you need. this way you could produce e.g.

0 0 0 0 0
0 0 0 0 1
0 0 0 1 0
...

the minimum width of your matrix is then given by nextpow2 of your number of rows, but if you need a broader matrix you are free to just use more bits

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

採用された回答

Matt J
Matt J 2021 年 8 月 1 日
編集済み: Matt J 2021 年 8 月 1 日
Something like this, perhaps?
n = 15; k = 10;
dec2bin( randperm(2^n,k) ) -'0'
ans = 10×15
1 0 1 0 1 0 0 1 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 0 0 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by