"griddata" results in much smaller values than original data
2 views (last 30 days)
Show older comments
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 Comments
KSSV
on 18 Apr 2023
Edited: KSSV
on 18 Apr 2023
I suspect your lon, lat values are not exactly corresponding to elev. While running the code did you see the warning?
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
I suspect the high values correspond to diplicate lon, lat and have been removed.
When you check
nx = length(unique(lon)) ;
ny = length(unique(lat)) ;
nx*ny is not equal to 579072.
Accepted Answer
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.
websave("manila.zip","https://www.mathworks.com/matlabcentral/answers/uploaded_files/1359608/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)
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(:))
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(:))
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));
% shading interp;
% whos
More Answers (1)
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)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!