create an interpolated grid

조회 수: 3 (최근 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 CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by