# How to interpolate in 2d with the 3rd variable as a vector?

조회 수: 4 (최근 30일)
UH 2023년 6월 2일
답변: Simon Chan 2023년 6월 3일
I have contour data and its x-y coordinates. I successfull plotted the data using griddata which shows contours around the points only. I want to interpolate the data in 2-dimension to have the plot spreaded over 160x60 grid. I tried using interp2(x,y,dt,x1,y1) but it gives error "Interpolation requires at least two sample points for each grid dimension." Is there a way the interpolation is carried out in 2-dimension and the contour shows up to the limits, or my data are insufficient for 2d interpolation?
I would appreciate help.
~Best
dt = [3.96 4.36 0.6 2.6 1.44 3.84 3.64 0.72];
x = [80 120 40 60 100 100 80 80];
y = [40 60 80 80 80 120 160 0];
[x1,y1] = meshgrid(0:20:160,0:20:160);
z1 = griddata(x,y,dt,x1,y1);
contourf(x1,y1,z1,'ShowText','on');
grid on

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

### 채택된 답변

Simon Chan 2023년 6월 3일
If you are using R2023a, you may use function fillmissing2.
dt = [3.96 4.36 0.6 2.6 1.44 3.84 3.64 0.72];
x = [80 120 40 60 100 100 80 80];
y = [40 60 80 80 80 120 160 0];
[x1,y1] = meshgrid(0:20:160,0:20:160);
z1 = griddata(x,y,dt,x1,y1);
idxNaN = isnan(z1);
znew = fillmissing2(z1,'nearest','MissingLocations',idxNaN);
contourf(x1,y1,znew,'ShowText','on');
grid on

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

### 카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by