Plot surface from Lat/Lon/Depth/Data with different size depth
8 views (last 30 days)
Show older comments
Hello,
I'm sure this question is already answered on this forum, but I can't find any answer that match my problem. So here's the thing:
I need to plot multiple surfaces from different lat, lon and depth coordinates but:
- Lat and Lon are 35x1 vectors
- Depth is a 100x1 vector that apply to all Lat/Lon couple
- Datas are 100x35 matrix (so depending Depth and Lat/Lon)
So when I try to plot with Surf(Lat,Lon,Depth,Data) it does'nt work (logical...). I tried different way to overcome the problem but I never managed to success. My best attempt was to use scatter3 with loops to plot by Lat/Lon couple one by one, but that's not really a perfect solution.
I'm sure there's a trick with meshgrid or repmat but I'm quite new to Matlab, and I can't figure out on my own how the dimension of each vector should imbricate (I understand in 2D, but 3D is out of my range...)
The result should look like this (without the bathymetric map):
Update: In attachment, an exemple of a set of data, lat, lon, depth with 100x108 dimension instead of 100x35, but the idea is the same
Answers (3)
Benjamin Thompson
on 11 Mar 2022
Edited: Benjamin Thompson
on 11 Mar 2022
This might help with a starting point. Of course you will fill in your own depth data and coordinates.
lat = 35:(1/35):36-1/35;
lon = -100:(1/35):(-99-1/35);
depth = zeros(35,35,100);
depth(:,:,1) = rand(35,35) - 50;
depth(:,:,2) = rand(35,35) - 100;
[LAT, LON] = meshgrid(lat, lon);
figure, surf(LAT, LON, depth(:,:,1));
hold on
surf(LAT, LON, depth(:,:,2));
1 Comment
Benjamin Thompson
on 11 Mar 2022
You can also use contour3 if you want the contour level lines by themselves, or surfc if you want the surface plus the contour lines.
Star Strider
on 11 Mar 2022
Try this —
LD1 = load('Data.mat');
Data = LD1.Us;
LD2 = load('Depth.mat');
Depth = LD2.Depth;
LD3 = load('Lat.mat');
Lat = LD3.lati;
LD4 = load('Lon.mat');
Lon = LD4.long;
DepIdx = @(d) find(Depth < d, 1, 'first');
ChooseDepth = -100; % Choose Nearest 'Depth' To This Value
Depthv = Data(DepIdx(ChooseDepth),:); % 'Depth' Column Corresponding To This Depth
Depthv = fillmissing(Depthv,'linear'); % Interpolate 'NaN' Values
[Lt,Lg] = ndgrid(Lat,Lon); % Matrices For 'griddata' Interpolation
DepSfc = griddata(Lat,Lon,Depthv, Lt,Lg); % Create Surface Matrix
figure
plot3(Lat, Lon, Depthv) % Line Plot
grid on
xlabel('Lat')
ylabel('Lon')
zlabel('Something')
title(sprintf('Depth = %.4f',Depth(DepIdx(ChooseDepth))))
view(-80,30)
figure
surf(Lat,Lon,DepSfc) % Surface Plot
hold on
% contour3(Lat,Lon,DepSfc, 'ShowText','on')
hold off
grid on
xlabel('Lat')
ylabel('Lon')
zlabel('Something')
title(sprintf('Depth = %.4f',Depth(DepIdx(ChooseDepth))))
view(-80,30)
I have no idea what this plots or what I am looking at.
Plotting contours will not work here because the levels are not unique.
.
3 Comments
Star Strider
on 14 Mar 2022
I would llike to know the code you wrote to plot those, since I obviously missed some dtails with respect to what the data actually are and how to interpret them.
Anabel Von
on 13 Mar 2023
Is there a way to plot the data as a surface section and vertical section simultaneously? (see image)![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323325/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323325/image.png)
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!