"griddata" results in much smaller values than original data

2 Ansichten (letzte 30 Tage)
jie hu
jie hu am 18 Apr. 2023
Kommentiert: jie hu am 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 Kommentare
KSSV
KSSV am 18 Apr. 2023
Bearbeitet: KSSV am 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.
jie hu
jie hu am 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chunru
Chunru am 18 Apr. 2023
Bearbeitet: Chunru am 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")
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));
% shading interp;
% whos

Weitere Antworten (1)

KSSV
KSSV am 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)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by