Generate 3D plots using 3D variables (Lat,lon,depth,Salinity)
10 ビュー (過去 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!





