这是一个包括缩放的更新版本:
%just some random input data VoxelGrid=randi(100,30,20,30)==1; %x axis: 1 voxel is 1 cm %y axis: 1 voxel is 2cm %z axis: 1 voxel is .5 cm resolution=[1,2,.5]; GridSize=size(VoxelGrid); for x = 1:GridSize(1) for y = 1:GridSize(2) for z = 1:GridSize(3) if VoxelGrid(x, y, z) %http://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube plotcube( resolution, ... [x, y, z].*resolution, ... 0.4, ... [1, 0, 0]) end end end end