create an interpolated grid
조회 수: 3 (최근 30일)
이전 댓글 표시
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');
댓글 수: 0
채택된 답변
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');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!