Clear Filters
Clear Filters

how to plot contour of 3D variable

36 views (last 30 days)
Amal MM
Amal MM on 17 Aug 2024 at 21:49
Commented: Voss on 20 Aug 2024 at 1:48
HI
I have issue with my data
I have salinity data with dimension (time,Lat,Lon) and I want to plot a filled 3-D contour
I want to plot salinity at specific
timestep 1:13
for example the size of variable
Lat=24*25;
Lon=24*25;
Salinty=744*24*25;
I am getting error becouse the X ,Y and Salinity had different size
I try for loop but it didn't worke
for i=1:12;
Sal(i,:,:)=Salinity(i,:,:);
figure
contourf(X,Y,Sal(i,:,:);
end
Can someone help?

Accepted Answer

Voss
Voss on 18 Aug 2024 at 23:46
Edited: Voss on 18 Aug 2024 at 23:47
Example data:
Salinity = rand(744,24,25);
[Lat,Lon] = ndgrid(1:24,1:25);
whos Lat Lon Salinity
Name Size Bytes Class Attributes Lat 24x25 4800 double Lon 24x25 4800 double Salinity 744x24x25 3571200 double
If you want a sequence of filled contours:
tmp = permute(Salinity,[2 3 1]);
whos tmp
Name Size Bytes Class Attributes tmp 24x25x744 3571200 double
for ii = 1:3 % first 3 times only
figure
contourf(Lon,Lat,tmp(:,:,ii));
end
Your code didn't work because Sal(i,:,:) is of size 1-by-24-by-25 but contourf expected a matrix of size 24-by-25.
In my suggested code, permute rearranges the dimensions of Salinity to make tmp, which is of size 24-by-25-by-744, so that each tmp(:,:,ii) is a matrix of size 24-by-25.
  2 Comments
Amal MM
Amal MM on 20 Aug 2024 at 1:17
Thank you I greatly appreciate it work
Voss
Voss on 20 Aug 2024 at 1:48
You're welcome!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 17 Aug 2024 at 22:58
In order to do 3D contours, you need to call isosurface . You would call it several times, once for each contour level.
However, filling the 3D contours is a bit of a problem.
I have to ask whether filling the contours is really necessary, as opposed to just drawing their surfaces? Since their entire surface would be drawn, the only visual difference between surface-only and surface-and-fill would be the visual effect of transparency -- showing darker locations where the view happens to strike more of the volume. That kind of visual hint is not without merits, but is it worth the trouble?

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!