A binary tensor may also be referred to as a 3D matrix of zeros and non-zeros or a 3D logical array. binaryTensorVoxel will draw cubes where there are non-zero entries in a tensor and leave vacancies where there are zeros. A simple use case example is
t = round(rand(3,3,3)); % zeros and ones
binaryTensorVoxel(t);
The thumbnail image for this File Exchange entry was drawn by applying binaryTensorVoxel to a 3D cellular automaton.
Hey Paul, GREAT idea.
You're gonna hate me for this though: it really slows down for large matrices.
The big speed hit comes from multiple calls to patch() within a loop.
I put together a more vectorised version that pre-calculates vertices/faces, then just calls patch the once. Here it is (all squashed up) below. It results in only one patch object, but it is ~1000x faster for a 20x20x20 binary matrix.
One thing I was expecting to work that didn't though is to be able to have different side lengths of the voxel, e.g:
binaryTensorVoxel(rand(3,3,3)>0.8,[0.5 0.5 1])
This is common in three dimensional imaging where the voxels have equal side lengths in row/column but the slices are at a different depth, rendering the voxel in a brick shape.