Q:

Combinations matrix in matlab

This code
 combinations = dec2base(0:power(2,N*M)-1,2) - '0'

generates all possible combinations of zeros and ones for a matrix of size N*M and stores all these combinations in a matrix called combinations. I need to know how it works , because i don't understand this code . Thank you 

A:

Consider M = 2, N = 3 as an example. Then power(2,N*M)-1 is 63, and 0:power(2,N*M)-1 is the vector [0 1 2 ... 63].
dec2base(..., 2) converts those 64 numbers into base 2, using chars '0' and '1' as "digits". Each result is in a row, left-padded with '0''s if needed. So it gives the 64×6 char matrix
000000
000001
000010
....
111110
111111

To convert those chars into numbers, subtract '0'. That gives 0 for '0' and 1 for '1', exploiting the fact that the ASCII codes for chars '0' and '1' are consecutive. So the final result is the numeric matrix
0     0     0     0     0     0
0     0     0     0     0     1
0     0     0     0     1     0
....
1     1     1     1     1     0
1     1     1     1     1     1

