フィルターのクリア

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

13 ビュー (過去 30 日間)
Julien Masson
Julien Masson 2022 年 3 月 11 日
回答済み: Anabel Von 2023 年 3 月 13 日
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
  2 件のコメント
KSSV
KSSV 2022 年 3 月 11 日
Attach your data.
Julien Masson
Julien Masson 2022 年 3 月 11 日
Done. Sorry for the inconvenience

サインインしてコメントする。

回答 (3 件)

Benjamin Thompson
Benjamin Thompson 2022 年 3 月 11 日
編集済み: Benjamin Thompson 2022 年 3 月 11 日
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 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 3 月 11 日
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
Star Strider 2022 年 3 月 11 日
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 件のコメント
Star Strider
Star Strider 2022 年 3 月 14 日
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 2022 年 3 月 14 日
編集済み: Julien Masson 2022 年 3 月 14 日
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.

サインインしてコメントする。


Anabel Von
Anabel Von 2023 年 3 月 13 日
Is there a way to plot the data as a surface section and vertical section simultaneously? (see image)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by