I am trying to create the above effect of smoothing or flattening a mesh. This mesh boundary is z = 2*exp(-(y-5).^2).*sin(x) + exp(-x.^2).*cos(y). The flattening should be done by creating a new z value of an interior point (excluding boundary points), where the new value is the average of 3x3 grid points centered at the point. I believe the z values of boundary points should not change.
Am I calculating the average incorrectly?
[x,y] = meshgrid(-10:0.5:10,-10:0.5:10);
z = 2*exp(-(y-5).^2).*sin(x) + exp(-x.^2).*cos(y);
while true
clf
surf(z);
ylim([-2,2])
n = input('Press enter to continue.');
sx0 = size(x);
sx = sx0(1);
sy = size(y);
ix = sx0(2); % number of elements along the x-axis
iy = sy(1); % number of elements along the y-axis
z1 = z;
% for each interior point
for i = 1:(ix-1)
for j = 2:iy
%compute the average for a 3x3 grid points.
z1(j, i) = (sum(z((i-1):(i+1),(j-3):(j+3)))); %ERROR HERE
pause(0.5);
end
end
end
