How avoid interpolated values between two clouds of scattered data?
Show older comments
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.
Accepted Answer
More Answers (1)
Gonzalo Duró
on 15 Feb 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 Comment
Christopher Wilkes
on 9 May 2018
This worked well for me, thanks!
Categories
Find more on k-Means and k-Medoids Clustering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!