Problem in using scatteredInterpolant

조회 수: 2 (최근 30일)
Zhou Ci
Zhou Ci 2021년 10월 4일
댓글: Walter Roberson 2021년 10월 4일
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
Zhou Ci
Zhou Ci 2021년 10월 4일
@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 2021년 10월 4일
Nothing can be done for that purpose. If you need integers then you should not be doing any kind of interpolation.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2021년 10월 4일
Use nearest method
F = scatteredInterpolant(..., 'nearest')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolating Gridded Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by