Cumulative Sum of a Vector - Syntax

前端 未结 3 1328
夕颜
夕颜 2021-01-25 08:42

I am trying to resolve why the following Matlab syntax does not work.

  1. I have an array A = [2 3 4 5 8 9...]
  2. I wish to create an indexed cumulative, for
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-25 09:36

    Actually what you are doing is s(1:10)= sum(A(1:[1,2,3...10])) what you should do is

    for i=1:10
        s(i)=sum(A(1:i))
    end
    

    hope it will help you

提交回复
热议问题