title: Understanding accumarray in Matlab
body: <p>I need to understand accumarray to write a code that I really need.</p>
  
  <p>I tried to understand <a href="http://www.mathworks.co.kr/kr/help/matlab/ref/accumarray.html" rel="nofollow">http://www.mathworks.co.kr/kr/help/matlab/ref/accumarray.html</a></p>
  
  <p>Most examples were clear.</p>
  
  <p>However, in the 1st example of Example 2, I thought</p>
  
  <p>(1,2)th element of B should be 1</p>
  
  <p>because </p>
  
  <pre><code>(1,2) = 1st, 2nd of subs
  1st, 2nd of vals = 101, 102
  sum(diff([101,102]))=1
  </code></pre>
  
  <p>Also, in the 2nd example of Example 2, I thought</p>
  
  <p>(1,2)th element of B1 should be 2 instead of -2</p>
  
  <p>because</p>
  
  <pre><code>(1,2) = 1st, 3rd of subs
  1st, 3rd of vals = 101, 103
  sum(diff([101,103]))=2
  </code></pre>
  
  <p>and also I thought</p>
  
  <p>(4,1)th element of B1 should be 1 instead of -1</p>
  
  <p>because </p>
  
  <pre><code>(4,1) = 5,6th of subs
  5,6th of vals = 105,106
  sum(diff([105,106]))=1
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Please correct, I need to understand accumarray in depth to write my own code.</p>