How avoid interpolated values between two clouds of scattered data?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
fabio
el 7 de Sept. de 2016
Editada: per isakson
el 9 de Mayo de 2018
I have an extreme sparse set of lat-lon scattered data and I need to estimate values in a regular grid. I would like to avoid to have interpolated values when I am far from data (for a given threshold), and rather having NaN in this case. Is there any practical option for doing this?
Here is an example (messy!) code:
% a. dummy scattered data (two clouds);
x=[rand(1,11).*100, rand(1,11).*100+400];
y=[rand(1,11).*100, rand(1,11).*100+400];
z=rand(1,22).*100;
scatter(x,y,30,z); colorbar; % plot
% b. interpolation
F=TriScatteredInterp(x',y',z'); % interpolant (I know I should not use TriScatteredInterp anymore..)
[xi,yi]=meshgrid([0:10:500],[0:10:500]);% values for regular grid
zi=F(xi,yi);% extract on my regular grid
%
figure(), surface(xi,yi,zi); % plot interpolated value
What I want is that not only in the convex hull, but also if no data are found within a given distance are set to NaN. it is a sort of clustering, I guess... is there any easy option or interpolation trick to do this? Any help is appreciated! thank you.
0 comentarios
Respuesta aceptada
John D'Errico
el 7 de Sept. de 2016
There is no way to do it without some effort on your part. It is not terribly hard to solve though.
A scattered interpolant will work within the convex hull of the data. But if you have two distinct point clouds, then the hole in between the clouds will still be part of the convex hull. Interpolation may well yield garbage predictions there, but points inside the convex hull but outside of the clouds themselves are still inside as far as a convex hull is concerned. The software cannot magically know what you want.
I'd suggest identifying the two distinct clouds. If you have no simple scheme to do so, then a clustering tool may be needed, so perhaps a k-means tool. Build the two convex hulls separately. Then use a test to see if the target point is inside the convex hull of EITHER cloud. (So actually two different tests.) If so, then and only then will you use a tool like scatteredInterpolant to interpolate within the appropriate point cloud.
2 comentarios
John D'Errico
el 9 de Mayo de 2018
If there are two distinct point clouds, even a simple linear discriminant analysis might suffice to split the clouds into two groups.
Más respuestas (1)
Gonzalo Duró
el 15 de Feb. de 2017
I hope this helps:
s = 0.7; % shrink factor between 1 and 0, play with it to obtain different envelops
k = boundary(x,y,s); % boundary of your points
in = inpolygon(xi,yi,x(k),y(k)); % identifies the points within the polygon
out = ~in;
zi(out) = NaN;
Best, Gonzalo
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!