Interpolation outside the domain - meshgrid and griddata

Hello Matlab community,
I need your knowledge on a problem.
I have three vectors, two of them being (x,y) pairs, and the third being T=f(x,y).
I used meshgrid in the following way:
x_grid = linspace(min(x),max(x),1000);
y_grid = linspace(min(y),max(y),1000);
[xq,yq]=meshgrid(x_grid , y_grid );
Now I can plot my data in the following way:
T_interp = griddata(X,Y,T,xq,yq);
figure
contour(xq,yq,T_interp )
I attach an image with the cotour plot, and the domain I need superimposed (grey circles).
As seen in the image, I get an interpolation outside the boundaries of the domain I need.
Is there a way to avoid that?
Many thanks and best regards.

2 Comments

Hello, I found some feasible options but it's not yet exactly what I need, and help from people that know better than me is needed.
I used the command "inpolygon" in the following way:
for r=1:size(T_interp ,1);
for c=1:size(T_interp ,2);
if inpolygon(xq(r,c),yq(r,c),x_poli,y_poli)==0;
data_grid_3(r,c) = NaN;
else
end
end
end
With x_poly and y_poly being the vertices of my domain.
The question now is, is there a way to extract the boundaries of the domain automatically? I could do it by hand as I did for this trial code, but my domain
* is 3D (I posted a 2D picture for simplicity) and doing it by hand leads to errors
* is noe exactly sharp, and I need to capture the curvatures as well.
I tried with "boundary" in the following way:
k = boundary(x,y);
figure
plot(x(k),y(k))
hold on
plot(x,y,'o','color',[0.5 0.5 0.5])
As you see in the image attached the boundary does not exactly catch my domain.
Does someone have a suggestion?
I really appreciate any help.
Best regards.
Yes it is very much possible to extract the boundary of the given domain. And using inpolygon is apt. Note that, you have used a loop for that, which in unnecessary and time consuming. Attach your data, so that we can help you further. Mean while, you can have a look on boundary to extract the boundaries of the grid.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2016a

Asked:

on 14 May 2018

Commented:

on 16 May 2018

Community Treasure Hunt

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

Start Hunting!