Problem in using scatteredInterpolant

2 vues (au cours des 30 derniers jours)
Zhou Ci
Zhou Ci le 4 Oct 2021
Hi,
I am doing interpolation here to get values from variable z according to the respective lat lon. My variables from hdf file are:
lat = 406x270;
lon = 406x270;
z = 2030x1354;
lat_i = imresize(lat,[2030 1354],'bilinear');
lon_i = imresize(lon,[2030 1354],'bilinear');
There's another text file that contains lat lon values in the form of column vector:
lat_txt = tab.lat; % extract the column of latitude values from text file (3798x1 double)
lon_txt = tab.lon; % extract the column of longitude values from text file (3798x1 double)
I've used scatteredInterpolant here for interpolation
F = scatteredInterpolant(lat_i(:), lon_i(:), z(:));
Res = F(lat_txt, lon_txt); % To get values of z according to the lat lon of text file
Problem is z conatin integers (0,1,2,3,4) and using scatteredInterpolant gives values (1, 1.838, 2.84, 2.139, 2, 2.0022, 1.0014, 3.339, 3.000, 2.779,3 etc). And this thing is effecting my results. Is there a way that I only get in the form of integers (0,1,2,3,4)?
Warning:
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Secondly, I want 0 and 1 to be removed from z before passing it through scatteredInterpolant. I assign NaN to pixels containing 0 and 1. Not sure whether it's fine or not. Any help will be highly appreciated.
  3 commentaires
Zhou Ci
Zhou Ci le 4 Oct 2021
@Walter Roberson what can possibly be done to avoid getting such values (1, 1.838, 2.84, 2.139, 2, 2.0022, 1.0014, 3.339, 3.000, 2.779,3). Any other function in MATLAB other than scatteredInterpolant?
Walter Roberson
Walter Roberson le 4 Oct 2021
Nothing can be done for that purpose. If you need integers then you should not be doing any kind of interpolation.

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 4 Oct 2021
Use nearest method
F = scatteredInterpolant(..., 'nearest')

Plus de réponses (0)

Catégories

En savoir plus sur Interpolating Gridded Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by