Slice Displaying Grids Instead of Color

Just like the title said, I have a problem with displaying the correct slice. I attach the said generated figure below. Also this is my test script:
tas = ncread("data\dary_ATM.2023030100.nc", "ta");
lat = ncread("data\dary_ATM.2023030100.nc", "lat");
lon = ncread("data\dary_ATM.2023030100.nc", "lon");
kz = ncread("data\dary_ATM.2023030100.nc", "kz");
time = ncread("data\dary_ATM.2023030100.nc", "time");
ta = ncread("data\dary_ATM.2023030100.nc", "ta"); ta = ta - 273.15;
ua = ncread("data\dary_ATM.2023030100.nc", "ua"); ua = ua(:, :, 1, 4);
va = ncread("data\dary_ATM.2023030100.nc", "va"); va = va(:, :, 1, 4);
wa = ncread("data\dary_ATM.2023030100.nc", "wa"); wa = wa(:, :, 1, 4);
[longrid, latgrid] = meshgrid(lon, lat);
kzlevel = 18;
kz2d = kz(kzlevel) * ones(size(longrid));
[x,y,z] = meshgrid(lon, lat, kz);
ta = squeeze(ta(:,:,:,1));
figure;
slice(x,y,z,ta,[],[],1:4);
colormap("turbo");
colorbar;
clim([0 50]);
axis xy;

2 Comments

hello
you need tp rovide the data file if you want someone to help you
Here is the attached file: OneDrive. Please let me know if it is not accessible. Thank you. The password is matlab11

Sign in to comment.

 Accepted Answer

Mathieu NOE
Mathieu NOE on 20 Jan 2025
Edited: Mathieu NOE on 20 Jan 2025
hello again
there was just one mistake : slice(x,y,z,ta,[],[],1:4); to be replaced with : slice(x,y,z,ta,[],[],kz(1:4));
because you want to use kz and not just the index values (1:4)
now , a second remark : each of your sliced data has a different mean value and low variation around this mean. This makes the rendering of the 4 slices very uniform and you don"t see the tiny variations in each slice.
also I added one line to hide the mesh ( If you like) so the rendering is a bit improved (in my eyes) :
at the end of the code I simply added some extra figure display for each slice so you see what I mean
Code updated
file = "data\dary_ATM.2023030100.nc";
% tas = ncread(file, "ta"); % duplicate (see below)
lat = ncread(file, "lat");
lon = ncread(file, "lon");
kz = ncread(file, "kz");
time = ncread(file, "time");
ta = ncread(file, "ta"); ta = ta - 273.15;
ua = ncread(file, "ua"); ua = ua(:, :, 1, 4);
va = ncread(file, "va"); va = va(:, :, 1, 4);
wa = ncread(file, "wa"); wa = wa(:, :, 1, 4);
[longrid, latgrid] = meshgrid(lon, lat);
kzlevel = 18;
kz2d = kz(kzlevel) * ones(size(longrid));
[x,y,z] = meshgrid(lon, lat, kz);
ta = squeeze(ta(:,:,:,1));
figure;
% slice(x,y,z,ta,[],[],1:4);
s = slice(x,y,z,ta,[],[],kz(1:4));
set(s,'edgecolor','none') % hide the mesh
colormap("turbo");
colorbar;
% clim([0 50]);
caxis([-80 -50]);
axis xy;
% have a look to each individual slice
for k = 1:4
figure,
mesh(ta(:,:,k))
colormap("turbo");
end

3 Comments

just for my own fun (and understanding) , I wanted to plot the entire data set (18 layers) as a scatter plot
again, we can see how difficult is it to distinguish the small variations on top of the mean value
file = "data\dary_ATM.2023030100.nc";
% tas = ncread(file, "ta"); % duplicate (see below)
lat = ncread(file, "lat");
lon = ncread(file, "lon");
kz = ncread(file, "kz");
time = ncread(file, "time");
ta = ncread(file, "ta"); ta = ta - 273.15;
ua = ncread(file, "ua"); ua = ua(:, :, 1, 4);
va = ncread(file, "va"); va = va(:, :, 1, 4);
wa = ncread(file, "wa"); wa = wa(:, :, 1, 4);
ta = squeeze(ta(:,:,:,1));
[x,y,z] = meshgrid(lon, lat, kz);
% just for me to see the whole picture
scatter3(x(:),y(:),z(:),20,ta(:),'filled') % draw the scatter plot
colormap("turbo");
colorbar;
Thank you so much!
as always, my pleasure !

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2024a

Community Treasure Hunt

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

Start Hunting!