Generate 3D plots using 3D variables (Lat,lon,depth,Salinity)
조회 수: 11 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





