在Matlab中简单的滑动窗口过滤器 [英] simple sliding window filter in Matlab

查看:527
本文介绍了在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];

然后,我只想查看指数1,2,3然后2,3,4。 ..然后8,9,10,所以最后的序列是长度为7.我可以做一个for循环,这很容易,但我不知道如何矢量化为Matlab。请帮助。

这是一个非常简单快捷的方法:

 >> min([A(1:(end-2)); A(2:(end-1)); A(3:end)],[],1)

ans =

2 2 3 3 3 5 8

编辑:既然你想要满函数...

pre $函数running_min = running_min(x,k)

xrep = repmat(x ,1,k);
xrep = reshape([xrep zeros(1,k)],length(x)+1,k);
running_min = min(xrep,[],2)';
running_min = running_min(1:end-k);


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.

解决方案

Here is one very simple and fast way to do it:

>> min([A(1:(end-2)); A(2:(end-1)); A(3:end)], [], 1)

ans =

     2     2     2     3     3     3     5     8

EDIT: Since you want a full function...

function running_min = running_min(x, k)

xrep = repmat(x, 1, k);
xrep = reshape([xrep zeros(1, k)], length(x)+1, k);
running_min = min(xrep, [], 2)';
running_min = running_min(1:end-k);

这篇关于在Matlab中简单的滑动窗口过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆