How to plot a surface with lat, lon and depth?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Mathieu NOE
el 13 de Nov. de 2023
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,'*')
:
Respuestas (2)
Star Strider
el 13 de Nov. de 2023
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
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 comentarios
Star Strider
el 15 de Nov. de 2023
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
el 14 de Nov. de 2023
Editada: Mathieu NOE
el 14 de Nov. de 2023
hello @Francesco
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 comentario
Mathieu NOE
el 14 de Nov. de 2023
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
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!