Moving Along
Ever wish you could easily perform some statistical calculations with a sliding window, but find convolution and filtering a bit daunting for this application? Then a set of new functions in Release R2016a might just be for you!
Contents
New Collection of Functions for Moving Operations
The new collection of functions for moving (or sliding) operations are: These functions complement the cum* functions, some of which have been in MATLAB for a long time, e.g., cumsum, and some of which are relatively new, e.g., * cummax.Find the sliding maxima
Of course you could always find a local maximum in MATLAB by using a for-loop and working your way down the data, but paying careful attention to the ends. Or, with judicious use of indexing and reshaping, you could get the answer in a more vectorized fashion. Now you can just get it!ndata = 100; data = 0.5*rand(ndata,1)+0.5; npts = 5; datamvmax = movmax(data, npts); plot(data,'g*') axis([0 100 0.4 1.1]) hold on plot(datamvmax,'b+') hold off
