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

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 Comment

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,'*')
:

Sign in to comment.

Answers (2)

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 Comments

Thanks for the prompt response! The data sample are these on the excel. First one is LAT then we have LON and DEPTH.
Can u give me the right passages to create the surface? Again thanks in advance!
It takes too long for the original data interpolation to render (most likely a matrix size problem), so I restricted it to 1/10 of the original size in the first plot. The second plot shows the data interpolated to a much smaller grid resolution.
Try this —
T1 = readtable('Total Data.xlsx')
T1 = 12572×3 table
LAT LONG DEPTH _______ ______ _____ -74.697 164.07 0 -74.697 164.07 -0.21 -74.697 164.07 -0.22 -74.697 164.07 -0.23 -74.697 164.07 -0.24 -74.697 164.07 -0.2 -74.697 164.07 -0.19 -74.697 164.07 -0.25 -74.697 164.07 -0.18 -74.697 164.07 -0.15 -74.697 164.07 -0.02 -74.697 164.07 0.11 -74.697 164.07 0.2 -74.697 164.07 0.28 -74.697 164.07 0.32 -74.697 164.07 0.34
DpI = scatteredInterpolant(T1.LAT, T1.LONG, T1.DEPTH) % Depth Interpolant
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
DpI =
scatteredInterpolant with properties: Points: [2137×2 double] Values: [2137×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
N = ceil(height(T1)/10);
Latv = linspace(min(T1.LAT), max(T1.LAT), N);
Lonv = linspace(min(T1.LONG), max(T1.LONG), N);
[Latm,Lonm] = ndgrid(Latv,Lonv);
Dp = DpI(Latm, Lonm);
figure
surf(Latm, Lonm, Dp, 'EdgeColor','none')
colormap(turbo)
xlabel('Latitude')
ylabel('Longitude')
zlabel('Depth')
title('Original Data (Decimated)')
N = 150;
Latv = linspace(min(T1.LAT), max(T1.LAT), N);
Lonv = linspace(min(T1.LONG), max(T1.LONG), N);
[Latm,Lonm] = ndgrid(Latv,Lonv);
Dp = DpI(Latm, Lonm);
figure
surf(Latm, Lonm, Dp, 'EdgeColor','none')
colormap(turbo)
xlabel('Latitude')
ylabel('Longitude')
zlabel('Depth')
title('Downsampled Data')
.
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?
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!

Sign in to comment.

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 Comment

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

Sign in to comment.

Asked:

on 13 Nov 2023

Commented:

on 15 Nov 2023

Community Treasure Hunt

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

Start Hunting!