create an interpolated grid

18 ビュー (過去 30 日間)
wassim boulala
wassim boulala 2020 年 9 月 3 日
コメント済み: wassim boulala 2020 年 9 月 4 日
Hi!
i have created with a simple line code a grid from a table of tree colums (X,Y cartesian coordinates) Z altitudes .i want to creat an interpolated grid (interpolate the Z values) with a step (delta x and delta y of 20). i tried this but it doesn't works . can you help me please?
clear;
format long e
%open file xyz
T=readtable('points.txt');
A=T{:,:};
X=A(:,1);
Y=A(:,2);
Z=A(:,3);
min_x=min(X);
max_x=max(X);
min_y=min(Y);
max_y=max(Y);
n=length(X);
[XX,YY] = meshgrid(linspace(min(X),max(X),100),linspace(min(Y),max(Y),72));
%first grid
ZZ = griddata(X,Y,Z,XX,YY);
% new interpolated grid
[xi,yi]=meshgrid(min_x:20:max_x,min_y:20:max_y);
bathimtry=interp2(X,Y,ZZ,xi,yi);
lonx=min_x:20:max_x;
laty=min_y:20:max_y;
%surf(XX,YY,ZZ);
%ZZ(ZZ>0)=nan;
figure(1)
%pcolor(XX,YY,ZZ),shading interp ,colorbar;
pcolor(lonx,laty,bathimtry),shading flat ,colorbar;
saveas(gcf,'bat_fine','eps');

採用された回答

KSSV
KSSV 2020 年 9 月 4 日
% new interpolated grid
lonx=min_x:20:max_x;
laty=min_y:20:max_y;
[Xi,Yi]=meshgrid(lonx,laty);
bathymetry=interp2(XX,YY,ZZ,Xi,Yi);
%surf(XX,YY,ZZ);
%ZZ(ZZ>0)=nan;
figure(1)
%pcolor(XX,YY,ZZ),shading interp ,colorbar;
pcolor(Xi,Yi,bathymetry),shading flat ,colorbar; % if error transpose bathymetry and see
saveas(gcf,'bat_fine','eps');
Also you can striaght away try this:
clear;
format long e
%open file xyz
T=readtable('points.txt');
A=T{:,:};
X=A(:,1);
Y=A(:,2);
Z=A(:,3);
min_x=min(X);
max_x=max(X);
min_y=min(Y);
max_y=max(Y);
n=length(X);
% new interpolated grid
lonx=min_x:20:max_x;
laty=min_y:20:max_y;
[Xi,Yi]=meshgrid(lonx,laty);
bathymetry=interp2(X,Y,Z,Xi,Yi);
ZZ = griddata(X,Y,Z,Xi,Yi);
%surf(XX,YY,ZZ);
%ZZ(ZZ>0)=nan;
figure(1)
%pcolor(XX,YY,ZZ),shading interp ,colorbar;
pcolor(lonx,laty,bathymetry),shading flat ,colorbar; % if error transpose the bathymetry
saveas(gcf,'bat_fine','eps');
  1 件のコメント
wassim boulala
wassim boulala 2020 年 9 月 4 日
i think that works , thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by