Generate 3D plots using 3D variables (Lat,lon,depth,Salinity)

조회 수: 11 (최근 30일)
Francesca Evans
Francesca Evans 2022년 9월 7일
댓글: Francesca Evans 2022년 9월 7일
Hey!
I've converted 4D-double variables from netCDF files and have these variables (i.e., temperature/salinity) in a three-dimensional double format (lon x lat x depth), I used [x y z ] = meshgrid(lon,lat,depth) in order to make each variable the same size. Each variable is a double, and looking at the forums and mathworks, I should be able to generate 3D plots (i.e., surfc/contour3). However, when I attempt to use these plot formats, I get errors such as X,Y,Z vectors must be the same length (which they are after using meshgrid?), or 'values must be scalar, vector or an array of numeric type' but again, after using TF = isnumeric(variable), each parameter used gets ans (1).
I've tried using the lon, lat and depth variables as they come (not meshgridded), but then I get errors with matrix dimensions must agree.
Does anyone know how to resolve these issues?

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 9월 7일
편집: Cris LaPierre 2022년 9월 7일
surfc and contour3 do not accept 3D variables as inputs. See here:
and here
Lat and Lon can be a vector or 2D matrix, and depth must be a 2D matrix.
  댓글 수: 7
Cris LaPierre
Cris LaPierre 2022년 9월 7일
편집: Cris LaPierre 2022년 9월 7일
Here's what I see for sizes
This means each page of Salinity corresponds to all lat/lon combos at a single depth. A contour plot is a good way to perhaps visualize the salinity at a single depth, but is not an appropriate visualization for all the data at all depths. For that, you may want to consider a scatter3 plot where the markers' size or color are based on salinity. Here are some examples.
load Depth.mat
load Lat.mat
load Lon.mat
load Salinity.mat
% contour plot for Salinity at a specific depth
contour3(Lat,Lon,Salinity(:,:,5))
title(["Salinity at Depth = " + Depth(5)])
colorbar
% scatter3: color set by salinity
[X,Y,Z] = meshgrid(Lat,Lon,Depth);
figure
scatter3(X(:),Y(:),Z(:),[],Salinity(:),'filled')
colorbar
I'm not convided the 3D visualization is adding anything, so I'd be more inclined to use a 2D contour plot here.
figure
contourf(Lat,Lon,Salinity(:,:,5))
title("Salinity at Depth = " + Depth(5))
colorbar
Francesca Evans
Francesca Evans 2022년 9월 7일
Hey Cris!
Thank you so much for all this assistance and guidance, the contourf plots look a lot better at what I'm trying to show, and I can always use subplots to show the change in salinity with different depths.
Cheers for this!!
Francesca :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by