title: Generate pairs of points using a nested for loop
body: <p>As an example, I have a matrix <code>[1,2,3,4,5]'</code>. This matrix contains one column and 5 rows, and I have to generate a pair of points like <code>(1,2),(1,3)(1,4)(1,5),(2,3)(2,4)(2,5),(3,4)(3,5)(4,5)</code>.</p>
  
  <p>I have to store these values in 2 columns in a matrix.  I have the following code, but it isn't quite giving me the right answer.  </p>
  
  <pre><code>for s = 1:5;
      for tb = (s+1):5;
      if tb&gt;s
          in = sub2ind(size(pairpoints),(tb-1),1);
          pairpoints(in) = s;
          in = sub2ind(size(pairpoints),(tb-1),2);
          pairpoints(in) = tb;
       end
      end
  end
  </code></pre>
  
  <p>With this code, I got <code>(1,2),(2,3),(3,4),(4,5)</code>. What should I do, and what is the general formula for the number of pairs?</p>