creat a grid from xyz file

Hi!
I have a file of X,Y,Z values (X,Y are cartesian coordinates) and Z the altitude (it's a topo-bathymetry file).
can you tell me please how to creat a grid which contains this altitudes .
thank you

回答 (1 件)

jonas
jonas 2020 年 8 月 27 日

1 投票

%make a 100x100 grid
[XX,YY] = meshgrid(linspace(min(X),max(X),100),linspace(min(Y),max(Y),100))
%interpolate Z data to grid
ZZ = griddata(X,Y,Z,XX,YY)

8 件のコメント

wassim boulala
wassim boulala 2020 年 8 月 27 日
yes thank you but how to visualized the result in a figure .
best,
jonas
jonas 2020 年 8 月 28 日
surf(XX, YY, ZZ)
wassim boulala
wassim boulala 2020 年 8 月 28 日
it seems to have an error.
in my file the size of X Y and Z is 8630. but when I use code its gives me a grid with 8630 X 8630. so it's not logical.
best,
jonas
jonas 2020 年 8 月 28 日
Probably you made a mistake, because the code works for me. Upload the data or provide some more information if you want more help.
wassim boulala
wassim boulala 2020 年 8 月 28 日
編集済み: wassim boulala 2020 年 8 月 28 日
here's my code
clear;
%open file xyz
T=readtable('points.txt')
A=T{:,:}
X=A(:,1);
Y=A(:,2);
Z=A(:,3);
n=length(X);
%make a nxn grid
[XX,YY] = meshgrid(linspace(min(X),max(X),n),linspace(min(Y),max(Y),n));
%interpolate Z data to grid
ZZ = griddata(X,Y,Z,XX,YY);
surf(XX,YY,ZZ)
jonas
jonas 2020 年 8 月 28 日
編集済み: jonas 2020 年 8 月 28 日
n is the resolution of the grid. Use a lower value like 100. However, you should get an OK graph anyway?
wassim boulala
wassim boulala 2020 年 8 月 28 日
how can i do a graph in 2D (X,Y) ?
i think that works.
jonas
jonas 2020 年 8 月 28 日
Sorry, but this is waste of time. I'll respond when you ask a coherent question.

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

カテゴリ

質問済み:

2020 年 8 月 27 日

コメント済み:

2020 年 8 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by