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

8 Ansichten (letzte 30 Tage)
Francesco
Francesco am 13 Nov. 2023
Kommentiert: Star Strider am 15 Nov. 2023
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 Kommentar
Mathieu NOE
Mathieu NOE am 13 Nov. 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,'*')
:

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Star Strider
Star Strider am 13 Nov. 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
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 Kommentare
Francesco
Francesco am 15 Nov. 2023
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 am 15 Nov. 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!

Melden Sie sich an, um zu kommentieren.


Mathieu NOE
Mathieu NOE am 14 Nov. 2023
Bearbeitet: Mathieu NOE am 14 Nov. 2023
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 Kommentar
Mathieu NOE
Mathieu NOE am 14 Nov. 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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by