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?

 Réponse acceptée

Walter Roberson
Walter Roberson le 29 Avr 2022

0 votes

I did not get around to gettting color working, but you can hardcode facecolor options into the patch() call.

6 commentaires

ac_bm_mat
ac_bm_mat le 29 Avr 2022
Can you please tell me what are x,y,z: It is centre of each voxel?
Walter Roberson
Walter Roberson le 29 Avr 2022
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.
ac_bm_mat
ac_bm_mat le 29 Avr 2022
Will Nx = 8; Ny = 8; Nz = 8; in my case?
Also will it be occupied = elem >0 in my case?
ac_bm_mat
ac_bm_mat le 29 Avr 2022
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?
Walter Roberson
Walter Roberson le 29 Avr 2022
Sorry, I am too busy the next few days to simplify that code for your case.
ac_bm_mat
ac_bm_mat le 29 Avr 2022
It's okay. Whenever you are free, please try to simplify it. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by