Summing up till a certain interval

前端 未结 1 1621
花落未央
花落未央 2020-12-11 12:09

How can I compute the summation of an interval. I will use Matlab\'s code for eg.

data=[1;2;3;4;5;6;7;8;9;10;11;12]

I would like to perform

相关标签:
1条回答
  • 2020-12-11 12:39

    No for loop needed, if indeed this interval is constant like in your example:

    Ans=sum(reshape(data,3,[]))
    

    note that I reshape the vector data to a matrix that has the right number of columns, so the value 3 relates to the interval size you wanted...

    0 讨论(0)
提交回复
热议问题