Generate 3D plots using 3D variables (Lat,lon,depth,Salinity)
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Francesca Evans
am 7 Sep. 2022
Kommentiert: Francesca Evans
am 7 Sep. 2022
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 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 7 Sep. 2022
Bearbeitet: Cris LaPierre
am 7 Sep. 2022
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 Kommentare
Cris LaPierre
am 7 Sep. 2022
Bearbeitet: Cris LaPierre
am 7 Sep. 2022
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





