Creating [-1 1] matrix given length n
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Ameer Hamza
le 22 Mar 2020
Modifié(e) : Ameer Hamza
le 22 Mar 2020
See combvec():
Length = 3;
x = mat2cell(repmat([1 -1], Length, 1), ones(Length,1), 2);
out = combvec(x{:})';
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!