⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfilt.m

📁 JLAB is a set of Matlab functions I have written or co-written over the past fifteen years for the p
💻 M
字号:
function[varargout]=vfilt(varargin)%VFILT  Filtering along rows without change in length.%%   Y=VFILT(X,FILTER) convolves FILTER with X along their rows and%   crops the result Y to be the same length as X. If FILTER is a%   number, a Hanning filter of that length is used.  %                                                                         %   By default, the roughly length(FILTER)/2 data points on each end%   of Y that are contaminated by edge effects are replaced with NANs.%   This option may be turned off with Y=VFILT(X,FILTER,'nonans').%%   [Y1,Y2,...YN]=VFILT(X1,X2,...XN,FILTER) also works.%%   The input arrays XI may have any dimensionality.%%   VFILT(X1,X2,...XN,FILTER); with no output arguments overwrites the%   original input variables.%%   'vfilt --t' runs a test.%%   Usage: y=vfilt(x,filter);%          y=vfilt(x,filter,'nonans');%          [y1,y2,y3]=vfilt(x1,x2,x3,filter);%   __________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information%   (C) 2000--2005 J.M. Lilly --- type 'help jlab_license' for details     %if strcmp(varargin{1}, '--t')%  vfilt_test,return%endif strcmp(varargin{1},'--t')    vfilt_test;returnendnarg=nargin;bnan=1;str='nan';if ischar(varargin{end})   str=lower(varargin{end});   varargin=varargin(1:end-1);   narg=narg-1;end% ndim=1;% if length(varargin{end})==1%    ndim=varargin{end};%    varargin=varargin(1:end-1);%    narg=narg-1;% endn=varargin{end};for i=1:narg-1    varargout{i}=vfilt1(varargin{i},n,str);end eval(to_overwrite(narg-1))function[smooth]=vfilt1(data,filter,str)if nargin==2, bnan=1;endif length(filter)==1	filter=hanning(filter);    filter=filter./sum(filter);endsmooth=zeros(size(data));a=round(length(filter)/2);N=size(data,1);n=length(filter);if N<=n  warning(['Not enough rows to filter the data with a ' int2str(n) ' filter'])endif res(n/2)==0   halfn=floor(n/2);else    halfn=floor((n-1)/2);endsd=size(data);data=reshape(data,[sd(1) prod(sd(2:end))]);for i=1:size(data,2)	temp=conv(data(:,i),filter);	smooth(:,i)=temp(a:a+N-1);	if strcmp(str(1:3),'nan')		smooth(1:halfn,i)=nan*ones(halfn,1);		smooth(N-halfn+1:N,i)=nan*ones(halfn,1);	endendsmooth=reshape(smooth,sd);% sd=size(data)% sdnew=[sd(1)+n sd(2:end)]% % %Add zeros at end% data(end+[1:n],:)=zeros([n sd(2:end)]);% data=data(:);% % smooth=conv(data,filter);% size(smooth)% smooth=reshape(smooth,sdnew);% % smooth=smooth(a:a+N-1,:);% if bnan%         smooth(1:halfn,i)=nan*ones(halfn,1);%         smooth(N-halfn+1:N,i)=nan*ones(halfn,1);% endfunction[]=vfilt_testx =[0 0 1 1 0 0]';y1=[0 1 2 2 1 0]';bool=aresame(y1,vfilt(x,[1 1 1]','nonnans'));reporttest('VFILT simple nonans', bool)x =[0 0 1 1 0 0]';y1=[nan 1 2 2 1 nan]';bool=aresame(y1,vfilt(x,[1 1 1]'));reporttest('VFILT simple nans', bool)x(:,:,1)=[0 0 1 1 0 0]';x(:,:,3)=[0 0 1 1 0 0]';y1(:,:,1)=[0 1 2 2 1 0]';y1(:,:,3)=[0 1 2 2 1 0]';bool=aresame(y1,vfilt(x,[1 1 1]','nonnans'));reporttest('VFILT 3-D matrix', bool)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -