MATLAB: How to get the same interpolation results using TRISCATTEREDINTERP for differently scaled data in MATLAB

MATLAB

I have x,y,z data. I want to use TRISCATTEREDINTERP for various y such that y=y/100, y=y/10, y=y*10 etc. to interpolate on a specified grid.
I notice that the interpolated results are different. The following code demonstrates the behavior:
x = rand(10,1);
y = rand(10,1);
z = x.^2 + y.^2;
for sFactor=[0.01 0.1 1 10 100]
% Scale Y
y2 = y/sFactor;
% Constrain the edges of the new triangulation so that they do not get swapped out
% This will violate the Delaunay criterion, but preserving the
% topology is more important in this usecase.
dtnew = DelaunayTri(x,y2);
% Create the interpolants
F = TriScatteredInterp(dtnew,z);
% Create the grid
xlin = linspace(min(x),max(x),300);
ylin = linspace(min(y2),max(y2),300);
[X,Y] = meshgrid(xlin,ylin);
% Evaluate Z
Z= F(X,Y);
% Visualization
figure;
step_value = -(min(min(z)) - max(max(z)))/40;
contour(X, Y, Z, 'Fill', 'on', 'LevelStep', step_value);
colorbar('peer',gca, 'Fontsize', 18);
end
Notice the variation/edges are not preserved in each case.

Best Answer

As the Y-Data is scaled and X-Data remains the same in each case, the Delaunay triangles created may be different which gives different results. In order to get the same interpolation results each time, you need to constrain the edges of the new triangulation so that they do not get swapped out. This will violate the Delaunay criterion, but preserve the topology, which is more relevant in this case.
The following code demonstrates this behavior:
x = rand(10,1);
y = rand(10,1);
z = x.^2 + y.^2;
% Create delaunay triangles
dt = DelaunayTri(x,y);
% Get the edges of the triangulation
E = dt.edges();
for sFactor=[0.01 0.1 1 10 100]
% Scale Y
y2 = y/sFactor;
% Constrain the edges of the new triangulation so that they do not get swapped out
% This will violate the Delaunay criterion, but preserving the
% topology is more important in this usecase.
dtnew = DelaunayTri(x,y2,E);
% Create the interpolants
F = TriScatteredInterp(dtnew,z);
% Create the grid
xlin = linspace(min(x),max(x),300);
ylin = linspace(min(y2),max(y2),300);
[X,Y] = meshgrid(xlin,ylin);
% Evaluate Z
Z= F(X,Y);
% Visualization
figure;
step_value = -(min(min(z)) - max(max(z)))/40;
contour(X, Y, Z, 'Fill', 'on', 'LevelStep', step_value);
colorbar('peer',gca, 'Fontsize', 18);
end