-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTwoD_moving_mean.m
28 lines (23 loc) · 948 Bytes
/
TwoD_moving_mean.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function meanvec = TwoD_moving_mean(Data,Window)
% Calculates a moving average for a given time-series of spatial series data. Please use an odd window size
stepnum1 = length(Data(:,1))-Window+1;
stepnum2 = length(Data(1,:))-Window+1;
meanvec = ones(floor(Window/2),floor(Window/2))*NaN;
for i = 1:stepnum1
for j = 1:stepnum2
%calcvec = removeNaN(Data(i:(i+Window-1),j:(j+Window-1)));
calcvec = Data(i:(i+Window-1),j:(j+Window-1));
if length(calcvec) == 0
meanvec(i,j) = [NaN];
else
meanvec(i,j) = [mean(mean(calcvec))];
end
end
if (mod(i-1,round(stepnum1/10))) == 0
(i-1)/round(stepnum1/10)/10
end
end
meanvec = [ones(floor(Window/2),length(Data(1,:)))*NaN; ...
ones(length(meanvec(:,1)),floor(Window/2))*NaN meanvec ones(length(meanvec(:,1)),floor(Window/2))*NaN; ...
ones(floor(Window/2),length(Data(1,:)))*NaN];
end