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

14 ビュー (過去 30 日間)
UH
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
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 Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by