MATLAB: How can I create a matrix of zeros and ones with dimension 2^n*n

create matrix

I want to build a matrix A of zeros and ones with dimension BxM.
Specifically, A contains all the possible dispositions of ones and zeros in M spaces considering also the order (hence, B=2^M).
for example when M=3
A=[1 1 1;
1 1 0;
1 0 1;
1 0 0;
0 1 1;
0 1 0;
0 0 1
0 0 0];

Best Answer

Try this:
Out = dec2bin(0:(2^M)-1)-'0'
produces:
Out =
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1