To avoid issues with the slicing surface's XData, YData and ZData not having a wide enough range for your volumetric data, generate XData, YData and ZData for the slicing surface manually.
For example, if you would like to slice volumetric data with a plane, start by writing an equation for the plane. A plane that is perpendicular to the XY plane and is rotated 45 degrees around the Z axes has a normal vector n=(-1 1 0). The plane is defined by the equation
where X=(x,y,z) is the point that lies on the plane and p=(px,py,pz) is the point that the plane passes through. For the given n=(-1,1,0) and letting the plane passes through the origin (p=(0,0,0)), the equation becomes:
To generate the data for the surface of this plane, create 2D arrays for X and Z (with a particular range) using MESHGRID, then use X and Z to calculate Y (although, as shown above, only X is necessary to calculate Y in this case).
[xg, zg] = meshgrid(linspace(0, 4.5), linspace(1, 3000));
yg = xg;
[x,y,z] = meshgrid(0:0.05:4.5 ,0:0.1:2.3,1:1:3000);
v = x.*exp(-x.^2-y.^2-z/100.^2);
figure
h = slice(x,y,z,v,xg,yg,zg);
set(h,'FaceColor','interp',...
'EdgeColor','none',...
'DiffuseStrength',.8)
axis tight
axis([0 4.5 0. 2.3 1 3000])
Best Answer