# "griddata" results in much smaller values than original data

3 views (last 30 days)
jie hu on 18 Apr 2023
Commented: jie hu on 20 Apr 2023
I am using "griddata" function to interpolate original data on query points. However, the interpolation value on the query points are much smaller than the original data. Is there any way to improve the interpolation?
##### 2 CommentsShow 1 older commentHide 1 older comment
jie hu on 18 Apr 2023
Yes, when I run 'IC_plot.m' matlab reports the duplicate points and removed them. averaged value is taken. My idea is to detect the duplicate points and take the biggest value on each point. Is that realizable?

Chunru on 18 Apr 2023
Edited: Chunru on 18 Apr 2023
It is due to the duplicate points in data. Griddata is averaging over the duplicate points to have a smaller value than peak. If you remove the duplicate points, then the result will be similar.
ans = '/users/mss.system.Ktq2V0/manila.zip'
unzip("manila.zip")
% plot x y z vector
data=importdata('manila.dat');
lon=data(:,2);
lat=data(:,3);
elev=data(:,4);
% Remove duplicate points
% [~, I, ~] = unique([lon lat], 'first', 'rows');
% lon = lon(I);
% lat = lat(I);
% elev = elev(I);
% Use peak for duplicated points
c = unique([lon lat], 'first', 'rows');
n = size(c,1)
n = 48256
lon1 = zeros(n, 1);
lat1 = zeros(n, 1);
elev1 = zeros(n, 1);
for i=1:size(c, 1)
idx = lon==c(i, 1) & lat==c(i,2);
lon1(i) = c(i, 1); lat1(i) = c(i, 2);
elev1(i) = max(elev(idx));
end
max(elev(:))
ans = 20.8693
plot3(lon,lat,elev,'.');
% xlin = linspace(min(lon)+0.2,max(lon)-0.2, 51);
% ylin = linspace(min(lat)+0.2,max(lat)-0.2, 201);
xr = (min(lon1):0.01:max(lon1));
yr = (min(lat1):0.01:max(lat1));
[X, Y]= meshgrid(xr,yr);
Z = griddata(lon1,lat1,elev1,X,Y,'natural');
max(Z(:))
ans = 20.8693
mesh(X,Y,Z)
% jump_grid = 1;
%
% figure
% surf(X(1:jump_grid:end,1:jump_grid:end), ...
% Y(1:jump_grid:end,1:jump_grid:end), ...
% Z(1:jump_grid:end,1:jump_grid:end));
% whos
jie hu on 20 Apr 2023
thanks very much for your help. It works!

KSSV on 18 Apr 2023
data=importdata('manila.dat');
lon=data(:,2);
lat=data(:,3);
elev=data(:,4);
xr = 118.7:0.2:121;
yr = 12.4:0.2:20.7;
[X, Y]= meshgrid(xr,yr);
idx = knnsearch([lon lat],[X(:) Y(:)],'k',10) ;
Z = reshape(max(elev(idx),[],2),size(X)) ;
plot3(lon(1:100:end),lat(1:100:end),elev(1:100:end),'o');
hold on
surf(X,Y,Z)
jie hu on 20 Apr 2023