필터 지우기
필터 지우기

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

조회 수: 12 (최근 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

답변 (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 CenterFile Exchange에서 Surface 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