0

I'm looking to create all possible binary combinations, in vectors of length 10, of values +1 and -1. Only two possible values, e.g.

x = [1 1 1 -1 1 -1 -1 1 -1 1]

...is one such combination. There are 2^10 == 1024 possible vectors of this format. Is there a nifty way of coming up with all of them (perhaps in a matrix of size 10x1024) with a few lines?

My application needs to test all input combinations of this type in a function. Right now the only solution I can think of is to construct 10 nested for-loops and in the very inside test x[a b c d e f g h i j] where the 10 characters iterate between +1 and -1. I'd rather not do that and learn something cool if possible. Cheers.

JDS
  • 16,388
  • 47
  • 161
  • 224

0 Answers0