3D cuboid elements display

elem(8,8,8) = zeros;
for i=1:8
elem(i,i,i)=1
end
I want to plot 3D voxels or mesh or elements with different color for 1 and different color for 0. How to do that?

 Accepted Answer

Walter Roberson
Walter Roberson on 29 Apr 2022
I did not get around to gettting color working, but you can hardcode facecolor options into the patch() call.

6 Comments

Can you please tell me what are x,y,z: It is centre of each voxel?
That code is aimed at creating 3D histograms by taking in continuous x, y, z points and figuring out how to divide the data up into bins, and then counting the number of hits in each bin.
In the code, occupied is a 3D logical array indicating whether the pixel has non-zero value or not (and thus has to be drawn) . It uses the indices of those locations together with the calculated boundaries of each edge in order to put together patch face and patch vertex information to use to draw around the entire occupied voxel.
Your elem array corresponds to my occupied array. But because my code was designed for histograms, the input x, y, z coordinates are used to figure out the x, y, z coordinates for drawing purposes.
Will Nx = 8; Ny = 8; Nz = 8; in my case?
Also will it be occupied = elem >0 in my case?
One more doubt. If the value of occupied is 0.8 for some voxel, 0.9 for some voxel and 1 for some voxel and 0 for all others. How to plot these things?
Also can you please simplify your original code and remove additional lines not required for my case?
Sorry, I am too busy the next few days to simplify that code for your case.
It's okay. Whenever you are free, please try to simplify it. Thank you so much.

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!