Plot 3D cylindrical voxels filled or empty (boolean)

Hi,
I have a matrix called h of size 9x36x20 [r, theta, z], containing 1's and 0's. Each number represent a voxel in a cylindrical figure. I would like to be able to plot in a 3d figure those with a 1 with some filled color, while leaving those with a zero transparent (could be with borders though, to make them look like a grid).
I would like to obtain something like this (drawn in inkscape, the matlab figure would be the whole cylinder with some red voxels).
Is it possible? I have already plotted some horizontal slices using patch to show the data at different heights, but this way is more representative

 Accepted Answer

I draw your data
clc,clear
cla
load example.mat
[m,n,k] = size(diff);
[r,t,z] = ndgrid(1:m,1:n,1:k);
[x,y] = pol2cart(t,r);
ix = logical(diff);
plot3(x(ix),y(ix),z(ix),'.r')
axis vis3d
Here is the result. It's hard to see anything. Can you explain more?

6 Comments

Thanks for plotting that! and for the interest!
OK, here goes the explanation. I'm finishing a PhD in Minerals Processing. I did some experiments using PEPT, to track the velocity and movement of some tracers inside a flotation cell (a mixing vessel). I tried different impeller designs, which should in turn generate different hydrodyanmics.
After the tests, I generated many of these 9x36x20 matrixes, having the velocity in each component, as well as the standard deviation.
That data is ready, and I produced some slice plots that show how the cell behaves for each design. I'm adding an example here
Finally, I generated a comparison matrix called diff (the one I posted and you plotted), that is obtained from doing voxel to voxel t-test, to see if two experiments generated similar results (0) or they are statistically different (1). Thus, the information I posted shows, voxel to voxel, the zones were two impeller design are statistically different. That's why I'm interested in generting a 3D representation, so I can show if two designs generate zonal differences or just random.
I hope this helps. The idea would be to show the data as you have, but instead of dots, show filled voxels, similar to my initial drawing.
BTW, I have many of those "diff" matrices, comparinf different designs or conditions, so some will look all red (completely different), while other will (hopefully) show differences only in the upper zone, or only on the walls, etc.
Thank you again!
This explains nothing actually
How do you want to obtain this plot/drawing
from this pointcloud
Each point in the pointcloud is a voxel, of 10mm radii, 10 mm height and 10°. Each point in the cloud would look like the red shape (voxel) of my drawing.
Here is the idea
clc,clear
t = (-15:15)*pi/180; % angle
[x1,y1] = pol2cart(t,1); % small arc
[x2,y2] = pol2cart(t,2); % large arc
z1 = x1*0;
z2 = x1*0+1;
xx = [x1; x2; x2; x1; x1];
yy = [y1; y2; y2; y1; y1];
zz = [z1; z1; z2; z2; z1];
surf(xx,yy,zz)
axis vis3d
Use rotate to rotate object
Use patch or surf to create side walls
You can rewrite this code as a function
function draw_voxel(t,r)
% code
end
Wow! Thank you very much!
Easy way to add walls
t = (-15:15)*pi/180; % angle
t = [t(1) t t(end)];
[x1,y1] = pol2cart(t,1); % small arc
[x2,y2] = pol2cart(t,2); % large arc
x2([1 end]) = x1([1 end]);
y2([1 end]) = y1([1 end]);

Sign in to comment.

More Answers (1)

Diego Mesa
Diego Mesa on 24 May 2020
Edited: Diego Mesa on 24 May 2020
Here I'm attaching some example data.
Also I'm showing a slice, so it's easier to understand what I need. Instead of presenting 20 horizontal slices (as z has 20 values), I need to build a 3D plot, showing all the voxels.
Thanks!

Asked:

on 23 May 2020

Commented:

on 25 May 2020

Community Treasure Hunt

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

Start Hunting!