create an interpolated grid

11 views (last 30 days)
wassim boulala
wassim boulala on 3 Sep 2020
Commented: wassim boulala on 4 Sep 2020
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');

Accepted Answer

KSSV
KSSV on 4 Sep 2020
% 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');

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!