Generating vectors of length N with only -1s and 1s.

1 view (last 30 days)
I want to generate some M number of vectors of length N with the entries restricted to -1s and 1s and the vectors should not be repetitive. Is it possible to do so? If yes, how?

Accepted Answer

Stephen23
Stephen23 on 17 Jun 2019
>> M = 5;
>> N = 19;
>> randi(0:1,M,N)*2-1
ans =
-1 1 -1 1 -1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 1
1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 1 1 -1 1
-1 1 -1 1 1 1 1 -1 1 -1 -1 -1 1 -1 1 1 1 1 -1
1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 -1
-1 -1 1 -1 -1 -1 1 1 1 1 1 -1 -1 1 1 1 1 1 1

More Answers (0)

Community Treasure Hunt

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

Start Hunting!