slice function starting from 1 and leaving empty space

I use the "slice" function in order to have a 3-D representation of the state of my system.
Why is there a large band of white useless spaces at the top and the right of the figure and a small one at the left and bottom (1 space wide) if I try to plot my matrix with slice(V,10,10,10)?
How can I shift the result by 1 toward the figure origin so that the whole figure is used to display the result?
I tried several things but I couldn't find a way to do that shift as I can't specify a 0 index for my matrix.

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 6월 11일
Plotting in MATLAB always plots against the index of the element unless otherwise specified. In this particular case, the volume slice is being plotted starting at (1,1,1) because the first index is (1,1,1). This is similar to the "plot" function which plots plot([4,6,3]); as the points (1,4), (2,6), (3,3).
To specify the indices of the volume elements, use the meshgrid function.
Note the definition for the size of the grid:
[X,Y,Z] = meshgrid(x,y,z) returns 3-D grid coordinates defined by the vectors x, y, and z. The grid represented by X, Y, and Z has size length(y)-by-length(x)-by-length(z).
For the slice function, use the following code to start the volume at the origin:
>> s = size(V);
>> [X,Y,Z] = meshgrid(0:s(2)-1, 0:s(1)-1, 0:s(3)-1);
>> slice(X,Y,Z,V,10,10,10);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품

릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by