mav.m

来自「王小平《遗传算法——理论、应用与软件实现》随书光盘」· M 代码 · 共 48 行

M
48
字号
function [out]=mav(v,n,all,in)
%
% mav.m
%
% Moving average filter
%
% v   = current variable
% n   = number of steps to include
% all = 0 to filter entire data set
% in  = input data
% out = processed data
%


[pD pL]=size(in);

out=in;

%
% Filter all the data
%
if all == 0
	for i = 1 : pL
		for j = n +1 : pD
			out(j,i)=mean(in(j-n:j,i));
		end
	end

	out(1:n,:)=in(1:n,:);
end


%
% Filter just the one column
%
if all == 1
	for j = n+1 : pD
		out(j,v)=mean(in(j-n:j,v));
	end

end


%
% Plot the current variable
%
plot(out(:,v));

⌨️ 快捷键说明

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