?? average.m
字號:
function y=average(n,w,glue)
%AVERAGE Weighted average.
% Y=AVERAGE(N,W) returns the weighted average of the vector N
% with weights given by the vector W.
% Y=AVERAGE(N,W,1) returns the weighted average of the vector N
% with weights given by the vector W, where the average for the first
% observations is calculated using a few last obs. and vice versa.
% Written by Rafal Weron (1997.02.12, rev. 2001.02.02)
% Copyright (c) 1997-2006 by Rafal Weron
if nargin<3,
glue = 0;
end;
n = n(:);
nn = length(n);
w = w(:);
ww = length(w);
k = floor(ww/2);
if ww/2 == k,
error('Weights vector W must have odd length.');
end;
if glue == 1,
n = [n(end-k+1:end)' n' n(1:k)']';
else
n = [ones(k,1)'*n(1) n' ones(k,1)'*n(nn)]';
end;
y = zeros(nn,1);
s = sum(w);
for i=1:nn,
y(i) = sum(w.*n(i:i+ww-1))/s;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -