Creating [-1 1] matrix given length n
Show older comments
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?
Accepted Answer
More Answers (1)
Ameer Hamza
on 22 Mar 2020
Edited: Ameer Hamza
on 22 Mar 2020
See combvec():
Length = 3;
x = mat2cell(repmat([1 -1], Length, 1), ones(Length,1), 2);
out = combvec(x{:})';
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!