title: sum of values in a column corresponding to first and last occurrence of a number in another column - matlab
body: <pre><code>a = [1 1 1 1 2 2 2 2 3 3 3 3; 1 2 3 4 5 6 7 8 9 10 11 12]';
  </code></pre>
  
  <p>What is the quickest way to sum the values in column 2 that correspond to the first and last occurrence of each number in column 1?</p>
  
  <p>The desired output:</p>
  
  <pre><code>1  5
  2  13
  3  21
  </code></pre>
  
  <p>EDIT: The result should be the same if the numbers in column 1 are ordered differently.</p>
  
  <pre><code>a = [2 2 2 2 1 1 1 1 3 3 3 3; 1 2 3 4 5 6 7 8 9 10 11 12]';
  
      2  5
      1  13
      3  21
  </code></pre>