# Volumetric slice plot missing data

3 views (last 30 days)
Sean Kelley on 4 Feb 2018
Answered: Bjorn Gustavsson on 3 Oct 2022
Matlab documentation provides the example below for a volumetric slice plot. The size of the 3D array is 17x21x26. However, the slice command only plots 16x20x25. Each axis is missing its last column/row of data points. Looking closely at the planar yslice=0, you can see that the y=0 plane is situated in the middle of a unit step. So basically, MATLAB is cutting one row/column of x, y, and z and not displaying the data then adjusting the plot to be symmetric by placing y=0 in the middle of a unit step. I'm plotting a 3D array called Temp_xtal with size of 128x128x12. (The rotated slice plot below has z-axis running left to right and looking at the y-z plane). When I plot... [xx,yy,zz] = meshgrid(-64:1:64,-64:1:64,1:1:12); xslice = 0; yslice = 0; zslice = 0; slice(xx,yy,zz,Temp_xtal,xslice,yslice,zslice) ...MATLAB returns an error. If I change it to [xx,yy,zz] = meshgrid(-64:1:63,-64:1:63,1:1:12); then it plots, but is missing a slice along the z-axis, even though zz ranges over 1:1:12. The plot only shows 11 of the 12 slices along my z-axis and 127 of the 128 slices along x-axis and y-axis (x-y planar slices are perpindicular to the page here, represented by vertical lines). Another observation is that the slice of missing data is actually slice#12, not slice #1. If I plot [xx,yy,zz] = meshgrid(-64:1:63,-64:1:63,0:1:11); then the data shifts left along z-axis, which is correct but still missing the 12th slice of data. This behavior is the same as what is shown in the MATLAB documentation example. Is there a way to plot all of my data without omitting the last slice?
Hans Ruder on 3 Oct 2022
I noticed the same problem. Seems to be a bug. Symmetric functions are not symmetric when plotting with slice.

Bjorn Gustavsson on 3 Oct 2022
This is a well-known feature of the pcolor-surf-slice functions. If they are given arrays x, y and V (for pcolor and surf) the value displayed on the patch with corners at [x(i1),y(i2)] - [x(i1+1),y(i2)] - [x(i+1),y(i2+1)] - [x(i1),y(i2+1)] will be the value V(i1,i2). The behaviour extends into 3-D with slice. While I was displaying many surfaces with few elements I wrote wrappers to these functions such that I could send in arrays x, y (and z) with coordinates for the corners of all elements in V such that matlab would show me the full surfaces. This was something as simple as:
function ph = pcolor_full(x,y,V)
Vfull = V;
Vfull(end+1,:) = Vfull(end,:);
Vfull(:,end+1) = Vfull(:,end);
ph = pcolor(x,y,Vfull);
end
This would work if I sent in x and y arrays one element smaller than V.
You should be able to do the same for slice.

### Categories

Find more on Surface and Mesh Plots in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!