function mvavg = mvavgmean(data,window);

L = length(data);
pm = (window-1)/2;
mvavg = ones(size(data))*NaN;

for p = pm+1:L-pm
 cdat = data(p-pm:p+pm); cdat(isnan(cdat))=[];
 if ~isempty(cdat);
  mvavg(p) = mean(cdat);
 end
end

mvavg([1:pm])=data([1:pm]); mvavg([L-pm:pm])=data([L-pm:pm]);
