Clear Filters
Clear Filters

How can I generate a plane to use with the SLICE command which is appropriately sized in MATLAB 7.8 (R2009a)?

1 view (last 30 days)
I am using the SLICE command to slice my data with a plane at a particular angle. I create a plane and then rotate it (with the ROTATE command) appropriately. However, the resulting plane is too small and I cannot see the volumetric data on the slice.
[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);
xmin = min(x(:)); ymin = min(y(:));
xmax = max(x(:)); ymax = max(y(:));
hslice = surf(linspace(xmin,xmax,100),...
linspace(ymin,ymax,100),...
zeros(100));
rotate(hslice,[1,0,0],90)
rotate(hslice,[0,0,1],45)
xd = get(hslice,'XData');
yd = get(hslice,'YData');
zd=get(hslice,'ZData');
delete(hslice)
h = slice(x,y,z,v,xd,yd,zd);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2009
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
dot(n,X-p)=0
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:
-x+y=0 => y=x
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).
% define the surface of the plane
[xg, zg] = meshgrid(linspace(0, 4.5), linspace(1, 3000));
yg = xg;
% define volumetric data
[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);
% generate the sliced data
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])

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!