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
Sai Teja Suggala
Sai Teja Suggala 2022년 3월 7일
Yes @Davide Masiello, I intend to expand it . My N would be 64. For which 2^64 would be my maximum number of columns. But I just want to limit it to say 1000 . Matrix of size ( 64 x 1000) with -1 and +1 as entries..given all columns are unique..

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

채택된 답변

Bruno Luong
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
A = 3×5
1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 1 -1

추가 답변 (2개)

David Hill
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
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)
Index in position 2 exceeds array bounds. Index must not exceed 893.

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


Jan
Jan 2022년 3월 7일
N = 3;
M = 8;
R = 1 - 2 * rem(floor(pow2(1-N:0).' .* (0:M-1)), 2)
R = 3×8
1 1 1 1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 -1 1 -1 1 -1 1 -1

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by