Filter löschen
Filter löschen

Plot surface from Lat/Lon/Depth/Data with different size depth

13 Ansichten (letzte 30 Tage)
Julien Masson
Julien Masson am 11 Mär. 2022
Beantwortet: Anabel Von am 13 Mär. 2023
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

Antworten (3)

Benjamin Thompson
Benjamin Thompson am 11 Mär. 2022
Bearbeitet: Benjamin Thompson am 11 Mär. 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 Kommentar
Benjamin Thompson
Benjamin Thompson am 11 Mär. 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.

Melden Sie sich an, um zu kommentieren.


Star Strider
Star Strider am 11 Mär. 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 Kommentare
Star Strider
Star Strider am 14 Mär. 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.
Julien Masson
Julien Masson am 14 Mär. 2022
Bearbeitet: Julien Masson am 14 Mär. 2022
Sure, here's an example for given datas:
%% load datas
close all; clear;
load ('Data.mat')
load ('Depth.mat')
load ('Lat.mat')
load ('Lon.mat')
%%
figure()
hold on
count=1; % init
for a=1:1:height(long)
lat3d(1:100,1)=lati(a);
lon3d(1:100,1)=long(a);
scatter3(lon3d,lat3d,Depth,5,Us(:,count),'filled'), view(-60,60)
count=count+1;
end
title('Zonal current during mission (Cross shelf)')
colormap(jet(14))
caxis([-0.35 0.35])
cbar=contourcbar('XTickLabel',{'-0.35','-0.30','','-0.20','','-0.10','','0','','0.1','','0.2','','0.3','0.35'},'XTick',-0.35:0.05:0.35);
title(cbar,'current in m/s')
And I repeat this operation with the other datasets that I have. It work well for long datasets (points are close to each other, so the visualisation is easy), but with datasets that are "sparse" the plot start to be difficult to read.

Melden Sie sich an, um zu kommentieren.


Anabel Von
Anabel Von am 13 Mär. 2023
Is there a way to plot the data as a surface section and vertical section simultaneously? (see image)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by