So briefly the points which are not supposed to be interpolated along large distances should assigned as NaN. is there a possibility to give a distance limit within points are allowed to be interpolated?
Set Tolerance Distance when Interpolating with Nearest Value
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello everybody, I have latitude(100x1) longitude(100x1) and height(100x1) of a river. I need to create a grid out of it therefore i have used meshgrid with min(lat), min(lon), max(lat), max(lon) and have latitude, longitude in a square matrix(100x100) form . As a second stage i need to interpolate the heights for each grid and have heights in matrix(100x100). However every interpolation method fills the grids even if they are not even correlated according to distance. It interpolates the edges which I don't want. I would like to interpolate only the values in river(or around it). I m also okay if it just takes nearest value but not larger than 10meters for example griddata(latitude, longitude, height, MESH_lat, MESH_lon, distance=10.0) or F = scatteredInterpolant(latitude, longitude, height,'linear','nearest',radius,1.0) then I can do MESH_H = F(MESH_lat,MESH_lon);
Hope I am clear what intended to do. Thank you for the support.
댓글 수: 3
William Rose
2022년 11월 23일
It is not clear to me what you want to do. Can you provide a small representative set of sample data? Instead of arrays with 82 million values in each, provide arrays with 30x40 points in each. Are the known heights located on a regular grid, and the locations where you want to interpolate irregularly spaced? Or vice versa? Do you want to create a set of points that are within a specified radius of a given point? If so, what is the location of the central point? Perhaps I will understand your question if you provide specific examples of each variable and array, of known heights and locaitons, and of desired query point locaitons. But don't let them be enormous, please.
답변 (1개)
William Rose
2022년 11월 24일
편집: William Rose
2022년 11월 24일
I assume you know the heights at scattered points, and you want to interpolate the heights to points on a grid, but you only want the grid to include points that are within radius R of a specified central point, c.
N=1000; %number of randomly scattered points
x=4*rand(N,1)-2; %N random x values in (-2,+2)
y=4*rand(N,1)-2; %N random y values in (-2,+2)
z=peaks(x,y); %height at each random point
F=scatteredInterpolant(x,y,z); %F=interpolant
xg=-2:.1:2; yg=-2:.1:2; %grid vectors
[X,Y]=meshgrid(xg,yg);
Zint=F(X,Y); %interpolated heights on the grid
c=[.35,.15]; %center point
R=0.5; %radius around c
xr=X(((X-c(1)).^2+(Y-c(2)).^2)<=R^2); %x values in region
yr=Y(((X-c(1)).^2+(Y-c(2)).^2)<=R^2); %y values in region
zr=F(xr,yr); %interpolated heights in the region
surf(X,Y,Zint,'EdgeColor','none'); %plot interpolated surface
xlabel('X'); ylabel('Y'); zlabel('Z'); hold on;
plot3(xr,yr,zr,'r*')
figure
surf(X,Y,Zint,'EdgeColor','none'); %plot interpolated surface
xlabel('X'); ylabel('Y'); zlabel('Z'); hold on;
plot3(xr,yr,zr,'r*')
axis equal; view(0,90) %view from above
Try it.
댓글 수: 2
William Rose
2022년 11월 24일
I think the GIS community, or GIS experts on this site, will have ideas for yhow to do this efficiently, but I do not.
It makes me thinkk of the 12 nautical mile and 234 nautical mile limits on charts, as seen below for the Florida Keys.
The GIS people have figured out waysa to do this efficiently.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolating Gridded Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!