title: Cumulative Sum of a Vector - Syntax
body: <p>I am trying to resolve why the following Matlab syntax does not work.   </p>
  
  <ol>
  <li>I have an array 
  A = [2 3 4 5 8 9...]</li>
  <li>I wish to create an indexed cumulative, for example
  s(1) = 2; s(2)=5, s(3)=9; ...  and so on</li>
  </ol>
  
  <p>Can someone please explain why the following does not work</p>
  
  <pre><code>x = 1:10
  s(x) = sum(A(1:x))
  </code></pre>
  
  <p>The logic is that if a vector is created for s using x, why would not the sum function behave the same way?  The above returns just the first element (2) for all x.</p>