title: Linear span of a vector in MATLAB
body: <p>I'm looking for a way to generate the spans of a given vector in MATLAB.</p>
  
  <p>For example:</p>
  
  <p>if <code>a = [ 0 1 0 1]</code> I need all vectors of the form <code>[0 x 0 y]</code>, 1 &lt;= x &lt;= max1, 1 &lt;= y &lt;= max2,.</p>
  
  <p>or if </p>
  
  <p><code>a = [ 0 1 0 1 1 0]</code> I need all vectors of the form <code>[0 x 0 y z 0]</code>, 1 &lt;= x &lt;= max1, 1 &lt;= y &lt;= max2, 1&lt;= z &lt;= max3.</p>
  
  <p>Note that the vector can have a variable number of 1's.</p>
  
  <p>My first impression is that I would need a variable number of for loops, though I don't know if that is doable in MATLAB. Also any other ideas are welcome!</p>