How to plot a surface with lat, lon and depth?

조회 수: 8 (최근 30일)
Francesco
Francesco 2023년 11월 13일
댓글: Star Strider 2023년 11월 15일
Hello, i am new to matlab and i am trying to learn. I have the lat, long, and depth values in three different columns, and i am trying to plot a surface but i cannot do it. Could you guide me step-by-step in realizing it?
Thanks in advance to everyone who will spend two minutes on this question!
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2023년 11월 13일
hello
and try the example given
load seamount
tiledlayout(2,1)
ax1 = nexttile;
ax2 = nexttile;
scatter3(ax1,x,y,z,'MarkerFaceColor',[0 .75 .75])
scatter3(ax2,x,y,z,'*')
:

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2023년 11월 13일
You will need to create a matrix from your data vectors. (It would help to have the actual data.)
Assuming they are similar to ‘lat’, ‘lon’, and ‘depth’ here, this should work —
N = 25;
lat = linspace(25,45,N).';
lon = linspace(100,120,N).';
[Lt,Ln] = ndgrid(lat, lon);
depth = sin(lat*lon.'*2*pi*6E-4) + rand(size(Lt))/5;
DpI = scatteredInterpolant(Lt(:), Ln(:), depth(:)) % Depth Interpolant
DpI =
scatteredInterpolant with properties: Points: [625×2 double] Values: [625×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
Latv = linspace(min(lat), max(lat), 125);
Lonv = linspace(min(lon), max(lon), 125);
[Latm,Lonm] = ndgrid(Latv,Lonv);
Dp = DpI(Latm, Lonm);
figure
surf(Latm, Lonm, Dp)
colormap(turbo)
xlabel('Latitude')
ylabel('Longitude')
zlabel('Depth')
.
  댓글 수: 4
Francesco
Francesco 2023년 11월 15일
Ok thanks. So the procedure of dealing with all my data and create a surface is only to modify this N = ceil(height(T1)/10) to N = ceil(height(T1))? Or am i missing something?
Star Strider
Star Strider 2023년 11월 15일
My pleasure.
You are correct with:
N = ceil(height(T1))
I had to decimate it to make it run here. (I suspect the matrix size was the problem, although running it here did not throw any specific errors, nor did it throw the time out error after running more than 55 seconds. It just seemed to hang. I just tried it again by dividing the height by 2 instead of 10 and it worked. There didn’t appear to be any change in the plot itself.)
If my Answer helped you solve your problem, please Accept it!

댓글을 달려면 로그인하십시오.


Mathieu NOE
Mathieu NOE 2023년 11월 14일
편집: Mathieu NOE 2023년 11월 14일
I wanted to show you how to use trisurf on scattered data but my example failed as it seems your data represent a 3D trajectory but not a surface
%% Making Surface Plots From Scatter Data
% How do you turn a collection of XYZ triplets into a surface plot?
%% Load the data
data = readmatrix('Total Data.xlsx'); % LAT LONG DEPTH
lat = data(:,1);
lon = data(:,2);
dep = data(:,3);
%%
% The problem is that the data is made up of individual (x,y,z)
% measurements. It isn't laid out on a rectilinear grid, which is what the
% SURF command expects. A simple plot command isn't very useful.
figure(1)
scatter3(lat,lon,dep,15,dep,'filled')
colorbar('vert')
%% Little triangles
% The solution is to use Delaunay triangulation. Let's look at some
% info about the "tri" variable.
tri = delaunay(lat,lon);
%% Plot it with TRISURF
figure(2)
h = trisurf(tri, lat,lon,dep);
axis vis3d
%% Clean it up
axis off
l = light('Position',[-50 -15 29])
set(gca,'CameraPosition',[208 -50 7687])
lighting phong
shading interp
colorbar EastOutside
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2023년 11월 14일
see example below for trisurf :
%% Making Surface Plots From Scatter Data
% How do you turn a collection of XYZ triplets into a surface plot?
%% Load the data
% data = readmatrix('Total Data.xlsx'); % LAT LONG DEPTH
% lat = data(:,1);
% lon = data(:,2);
% dep = data(:,3);
load seamount
lat = x;
lon = y;
dep = z;
%%
% The problem is that the data is made up of individual (x,y,z)
% measurements. It isn't laid out on a rectilinear grid, which is what the
% SURF command expects. A simple plot command isn't very useful.
figure(1)
scatter3(lat,lon,dep,15,dep,'filled')
colorbar('vert')
%% Little triangles
% The solution is to use Delaunay triangulation. Let's look at some
% info about the "tri" variable.
tri = delaunay(lat,lon);
%% Plot it with TRISURF
figure(2)
h = trisurf(tri, lat,lon,dep);
axis vis3d
%% Clean it up
axis off
l = light('Position',[-50 -15 29])
set(gca,'CameraPosition',[208 -50 7687])
lighting phong
shading interp
colorbar EastOutside

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by