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

9 次查看(过去 30 天)
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
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

更多回答(0 个)

类别

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