Creating [-1 1] matrix given length n
Mostrar comentarios más antiguos
Hi,
I want to create N length long [-1 1] matrix,
For example: Length=2
Output:
[ 1 1
1 -1
-1 1
-1 -1]
Length = 3
Output:
[ 1 1 1
1 1 -1
1 -1 1
-1 1 1
......
-1 -1 -1]
And so on, How can do that?
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 22 de Mzo. de 2020
Editada: Ameer Hamza
el 22 de Mzo. de 2020
See combvec():
Length = 3;
x = mat2cell(repmat([1 -1], Length, 1), ones(Length,1), 2);
out = combvec(x{:})';
Categorías
Más información sobre MATLAB 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!