Filter löschen
Filter löschen

Interpolation outside the domain - meshgrid and griddata

3 Ansichten (letzte 30 Tage)
Maria Angela Agizza
Maria Angela Agizza am 14 Mai 2018
Kommentiert: KSSV am 16 Mai 2018
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 Kommentare
Maria Angela Agizza
Maria Angela Agizza am 15 Mai 2018
Bearbeitet: Walter Roberson am 15 Mai 2018
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.
KSSV
KSSV am 16 Mai 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by