How to generate a matrix with entries of -1 and +1 of size N x M where all the columns are unique ?
1 回表示 (過去 30 日間)
古いコメントを表示
I want to create a matrix of size N x M, where each matrix element can be either -1 or +1 . The matrix must have unique columns
For N = 2, maximum number of 2 sized vectors possible with -1 and +1 are 2^N .
So, for N =2 and M =4
matrix would be
1 1 -1 -1
1 -1 1 -1
So, for a given N and M . I must get said matrix
Thanks a lot before hand.
3 件のコメント
採用された回答
Bruno Luong
2022 年 3 月 7 日
編集済み: Bruno Luong
2022 年 3 月 7 日
N = 3;
M = 5;
A = (dec2bin(randperm(2^N,M)-1,N)-'0')'*2-1
0 件のコメント
その他の回答 (2 件)
David Hill
2022 年 3 月 7 日
M=10;N=7;
m=unique((-1).^randi(2,2*M,N),'rows')';
m=m(1:N,1:M);
1 件のコメント
Bruno Luong
2022 年 3 月 9 日
Sorry but you accepted answer is not robust
N=10;
M=2^N; % 1024
m=unique((-1).^randi(2,2*M,N),'rows')';
m=m(1:N,1:M)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!