Code covered by the BSD License  

Highlights from
SLIDEFUN (v4.0, sep 2008)

5.0

5.0 | 4 ratings Rate this file 18 Downloads (last 30 days) File Size: 3.46 KB File ID: #12550

SLIDEFUN (v4.0, sep 2008)

by Jos (10584)

 

05 Oct 2006 (Updated 26 Sep 2008)

apply function to a moving window over a vector

| Watch this File

File Information
Description

R = SLIDEFUN(FUN, W, V) evaluates the function FUN to a moving window of W consecutive elements of the vector V.

The function FUN is specified by a function handle or a function name and should return a scalar for a vector input. W specifies the size of the window and should be a positive integer. At the two edges of the vector less than W elements will be used. R will have the same size as V.

Effectively SLIDEFUN applies the function FUN to a moving window of consecutive elemens V(x0:(x0+W)) using FEVAL, and returns the result in R(x).

The window [x0:(x0+W)] is relative to the current point x in V. R = SLIDEFUN(FUN, W, V, WINDOWMODE) denotes the type of windowing being used: central (default), backward and forward.
 
R = SLIDEFUN(FUN,W,V,WINDOWMODE, P1,P2,...) provides for aditional parameters which are passed to the function FUN.
    
Example 1) Sliding max filter - return the maximum of every three consecutive elements:
  V = [1 2 3 9 4 2 1 1 5 6] ;
  R = slidefun(@max, 3, V)
  % -> [2 3 9 9 9 4 2 5 6 6]
  % So R(i) = max(R(i-1:i+1)) ;
  % and R(1) = max(V(1:2))

More examples are provided in the help section.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
22 Jan 2007 John D'Errico

Nice, well written utility. It allows you to apply any general function on a moving window. Good help, examples, error checks, well done.

02 Apr 2008 Dan Haeg

Very useful code for me, thanks for plugging it on CSSM so I could find it.

26 Sep 2008 Carlos Adrian Vargas Aguilera

I just found I haven't rate it. Well done, and waiting for annonymous function for inputs... :)

Carlos

16 Nov 2010 Peter

Very helpful for technical analysis of stock data. Thank you good sir.

Please login to add a comment or rating.
Updates
26 Sep 2008

can now handle (anonymous) funtion handles properly

Tag Activity for this File
Tag Applied By Date/Time
matrices Jos (10584) 22 Oct 2008 08:42:51
moving Jos (10584) 22 Oct 2008 08:42:51
window Jos (10584) 22 Oct 2008 08:42:51
running Jos (10584) 22 Oct 2008 08:42:51
function Jos (10584) 22 Oct 2008 08:42:51
average Jos (10584) 22 Oct 2008 08:42:51
surrounding Jos (10584) 22 Oct 2008 08:42:51
filter Jos (10584) 22 Oct 2008 08:42:51
feval Jos (10584) 22 Oct 2008 08:42:51
matrix Jos (10584) 22 Oct 2008 15:06:07
moving Scott 29 Apr 2011 23:43:42
running Scott 29 Apr 2011 23:43:46

Contact us at files@mathworks.com