MATLAB slice in MATLAB®
Learn how to make 3 slice charts in MATLAB, then publish them to the Web with Plotly.
Volume Data Along Slices
Show volumetric data along slice planes that are orthogonal to each axis.
Create slice planes through the volume defined by v=xe-x2-y2-z2, where x, y, and z range from [-2,2]
. Create slice planes orthogonal to the x-axis at the values -1.2,
0.8, and
2and orthogonal to the z-axis at the value
0`. Do not create any slice planes that are orthogonal to the y-axis by specifying an empty array.
[X,Y,Z] = meshgrid(-2:.2:2); V = X.*exp(-X.^2-Y.^2-Z.^2); xslice = [-1.2,0.8,2]; yslice = []; zslice = 0; slice(X,Y,Z,V,xslice,yslice,zslice) fig2plotly()
Volume Data Along Surface
Show volumetric data along a nonplanar slice. Define the surface where you want to show the volumetric data.
Create volume array V
as the volume defined by v=xe-x2-y2-z2, where x, y, and z range from [-5,5]
. Then, show a slice of the volume data along the surface defined by z=x2-y2.
[X,Y,Z] = meshgrid(-5:0.2:5); V = X.*exp(-X.^2-Y.^2-Z.^2); [xsurf,ysurf] = meshgrid(-2:0.2:2); zsurf = xsurf.^2-ysurf.^2; slice(X,Y,Z,V,xsurf,ysurf,zsurf) fig2plotly()
Specify Interpolation Method
Create a slice plane through volumetric data. Specify the interpolation method for the data values.
Create a slice plane orthogonal to the x-axis at the value 0.8. Since the volume data is not defined for x values of 0.8, the slice
function interpolates the nearby values. To use the nearest data point value, specify the interpolation method as 'nearest'
.
[X,Y,Z] = meshgrid(-2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0.8;
yslice = [];
zslice = [];
slice(X,Y,Z,V,xslice,yslice,zslice,'nearest')
fig2plotly()