How can I generate 3D matrix for different shapes?

4 views (last 30 days)
Hi,
I am trying to generate 3D matrices for different shapes as given in below figure like cylinders, cylinder with holes or donut shape etc.
I tried to generate cube with some inner cubes in 3D using following codes as below.
% numbers are arbitrary
cube=zeros(11,11,11);
cube(3:9,3:9,3:9)=5; % Create a cube inside the region
% Boring: faces of the cube are a different color.
cube(3:9,3:9,3)=2;
cube(3:9,3:9,9)=2;
cube(3:9,3,3:9)=2;
cube(3:9,9,3:9)=2;
cube(3,3:9,3:9)=2;
cube(9,3:9,3:9)=2;
vold3d('Cdata',cube,'alpha',cube/5)
and I got results as below
</matlabcentral/answers/uploaded_files/98386/shapes1.png> Even I could generate these shapes in cartesisan co-ordinate system. But I couldn't generate as matrix.
How can I generate 3D matrix for above mentioned shapes. This matrix can be 128x128x128 or512x512x512 size. Can anyone help

Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!