1

I want to store in a matrix all the vectors that are created by the hypercube in dimension n, that is, for dimension n=3 for example :

matrix = [[0 0 0], [0 0 1], [0 1 0], [0 1 1],
          [1 0 0], [1 0 1], [1 1 0], [1 1 1]]

Is there a good way to do it in scilab ?

Thank you !

Flewer47
  • 145
  • 5

1 Answers1

1

Maybe this way (this is just like counting from 0 to 2^n-1 in binary)

n=3;
mat = zeros(2^n,n);
for i = 1:2^n
    mat(i,:) = bitget(i-1,1:n); 
end

--> mat
 mat  = 

   0.   0.   0.
   1.   0.   0.
   0.   1.   0.
   1.   1.   0.
   0.   0.   1.
   1.   0.   1.
   0.   1.   1.
   1.   1.   1.
Stéphane Mottelet
  • 2,853
  • 1
  • 9
  • 26