How to generate a matrix with entries of -1 and +1 of size N x M where all the columns are unique ?
Mostrar comentarios más antiguos
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 comentarios
Davide Masiello
el 7 de Mzo. de 2022
I guess for such a small matrix it is most convenient to just manually code it, unless you intend to expand your code to more general purposes, in which case it would be helpful to know what the latter are.
Sai Teja Suggala
el 7 de Mzo. de 2022
Bruno Luong
el 7 de Mzo. de 2022
What are typically values of N and M ?
Respuesta aceptada
Más respuestas (2)
David Hill
el 7 de Mzo. de 2022
M=10;N=7;
m=unique((-1).^randi(2,2*M,N),'rows')';
m=m(1:N,1:M);
1 comentario
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)
N = 3;
M = 8;
R = 1 - 2 * rem(floor(pow2(1-N:0).' .* (0:M-1)), 2)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!