필터 지우기
필터 지우기

Interpolation outside the domain - meshgrid and griddata

조회 수: 3 (최근 30일)
Maria Angela Agizza
Maria Angela Agizza 2018년 5월 14일
댓글: KSSV 2018년 5월 16일
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
Maria Angela Agizza
Maria Angela Agizza 2018년 5월 15일
편집: Walter Roberson 2018년 5월 15일
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 2018년 5월 16일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by