title: How to generate all possible combinations n-bit strings?
body: <p>Given a positive integer n, I want to generate all possible n bit combinations in matlab.<br>
  For ex : If n=3, then answer should be</p>
  
  <pre><code>000
  001
  010
  011
  100
  101
  110
  111
  </code></pre>
  
  <p>How do I do it ?
  I want to actually store them in matrix. I tried  </p>
  
  <pre><code>for n=1:2^4 
  r(n)=dec2bin(n,5); 
  end; 
  </code></pre>
  
  <p>but that gave error "In an assignment A(:) = B, the number of elements in A and B must be the same.</p>