Page 1 of 1
Matlab question : Chain addition and multiplication
Posted: August 13th, 2007, 10:46 am
by amitbatra
Hi All,Is there an inbuilt matlab command for performing chain (recirsive or I don't know what to call it), addition and multiplication.In the sense, a=[1, 2, 3, 4]Applying rcursive_addition(a) should yield [1, 1+2, 1+2+3, 1+2+3+4].And similarly multiplication.I do not want to use 'for' loop.Thanks for your attention.
Matlab question : Chain addition and multiplication
Posted: August 13th, 2007, 10:50 am
by mikeoz
cumsum(a) and cumprod(a)
Matlab question : Chain addition and multiplication
Posted: August 13th, 2007, 3:41 pm
by amitbatra
so I was only a minute away from my answer... thanks so much mikeoz.
Matlab question : Chain addition and multiplication
Posted: August 14th, 2007, 7:22 pm
by msperlin
Also take a look at filter() for the cases where you want to sum x elem at a time. It is flexible (eg. sum only the t-3 and t-1) and extremely fast.For products it would not suit though....