Matlab中的简单滑动窗口滤波器
我没有 nlfilter
包,而且我不太遵循 此示例。
我有一个非常简单的函数 fun
,我想将其应用于数组的移动窗口。数组是 Nx1
,我想查看长度 k
间隔。因此,对于 N=10
和 k=3
和 fun = @(x) min(x);
我会得到
A = [13 14 2 14 10 3 5 9 15 8];
filter(A,k,fun) = [2 2 2 3 3 3 5 8];
Here 我只想查看索引 1,2,3,然后 2,3,4,然后...然后 8,9,10,所以最终序列的长度为 7。我可以使用 for 循环轻松完成此操作,但我不知道如何为 Matlab 对其进行矢量化。请帮忙。谢谢。
I don't have the package for nlfilter
and I didn't quite follow this example.
I have a really simple function fun
and I want to apply it to a moving window of an array. The array is Nx1
, and I want to look at length k
intervals, say. So for N=10
and k=3
and fun = @(x) min(x);
I would get
A = [13 14 2 14 10 3 5 9 15 8];
filter(A,k,fun) = [2 2 2 3 3 3 5 8];
Here I only want to look at indices 1,2,3 then 2,3,4 then ... then 8,9,10, so the final sequence is length 7. I can do this easy with a for loop, but I have no idea how to vectorize it for Matlab. Help, please. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提到的帖子给出了构建的通用解决方案滑动窗口(您可以控制:重叠与不同、滑动步长、重叠量、窗口大小)
在您的情况下,它要简单得多,可以使用 HANKEL 函数:
如果您想构建一个可重用的解决方案:
我们将其用作:
注意,我使用 CELLFUN 以防
fcn
无法在矢量化中跨维度操作方式...The post you mentioned gave a general solution for building sliding windows (you could control: overlapping vs. distinct, slide step, overlap amount, windows size)
In your case, it is much simpler and can be easily performed with the HANKEL function:
If you want to build a reusable solution:
which we use as:
Note I am using CELLFUN in case
fcn
cannot operate across dimensions in a vectorized manner...这是一种非常简单快捷的方法:
编辑:因为你想要一个完整的功能......
Here is one very simple and fast way to do it:
EDIT: Since you want a full function...