From: ke on 4 May 2010 15:47 I would like advice on how to speed up a 'moving window' type of calculation. I have a function that calculates the final capacity of a battery as a function of an input time series of the energy going into and out of the battery, as well as the initial battery capacity: FinalBatteryCapacity = find_battery_capacity(Time, EnergyInOutOfBattery, InitialBatteryCapacity) ; The input time series is 20 years long, and I want to select 3-year segments using a moving window, then calculate the final battery capacity of each 3-year segment. Since the input time series are hourly (20 * 365 * 24 = 175200 elements), I want to avoid a slow for loop, but am concerned about memory issues if I vectorize the for loop into a matrix. Any suggestions?
From: K E on 4 May 2010 16:01 Just found Jos van der Geest's function slidefun.m in the user contributed directory and will try that.
From: ImageAnalyst on 4 May 2010 16:01 Have you tried the conv() function? I believe it is already optimized. If you're simply summing the elements, this would work. If you need to do something more complex, you might have to use blockproc() or nlfilter()
From: K E on 5 May 2010 14:35 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <3334c9a6-1c2e-4a69-bf2b-3ed66e80fe1d(a)24g2000yqy.googlegroups.com>... > Have you tried the conv() function? I believe it is already > optimized. If you're simply summing the elements, this would work. > If you need to do something more complex, you might have to use > blockproc() or nlfilter() My function is more complex, but unfortunately I don't have the image processing toolbox for blockproc and nlfilter. I may still be able to do this with slidefun.m but will need to change the function that I apply to each block. Slidefun requires the function to return a scalar value when a vector is passed in, such as taking the mean of a vector.
|
Pages: 1 Prev: Determine if a simulink block exists Next: drawing on a matlab figure in guide |