slidefun

版本 5.0.0.0 (6.3 KB) 作者: Jos (10584)
apply function to a moving window over a vector (v5, jan 2018)
6.5K 次下载
更新时间 2018/1/29

查看许可证

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.

Part of it's functionality has been implemented in base matlab (e.g. by movsum, movmean)

引用格式

Jos (10584) (2024). slidefun (https://www.mathworks.com/matlabcentral/fileexchange/12550-slidefun), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2017b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Data Type Conversion 的更多信息
致谢

参考作品: movingstd & movingstd2

启发作品: Sound Pressure Level Calculator

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
5.0.0.0

removed feval calls, updated help

1.1.0.0

fixed narginchk warning, treat V always as a vector even when it is a matrix

1.0.0.0

can now handle (anonymous) funtion handles properly