how can i create a cube represented by ones with a cylinder represented by zeros inside

2 views (last 30 days)
I am wondering if somebody can help me create a cube (say NxNxN matrix of ones) which is simply a = ones(N, N, N) but will have a cylinder inside represented by zeros.
Basically, what i want is to have a 3D matrix that has ones and zeros representing the cube encapsulating the cylinder.
Thank you.

Answers (1)

Image Analyst
Image Analyst on 18 Feb 2014
Then use cat() or repmat() to replicate the 2d array as many times in the 3D direction as you need. It's easy - give it a try.
  2 Comments
Ping
Ping on 18 Feb 2014
Thank you. But is there a way to avoid repmat() or cat()? SInce i was planning to extend the idea on having two or more cylinders intersecting inside the cube.
Image Analyst
Image Analyst on 18 Feb 2014
Edited: Image Analyst on 18 Feb 2014
Well those are the easiest ways, but you could just index everything to a plane in the z direction though I don't know why you'd want to do it that way since it's a little trickier. But how you extend into 3D vertically is totally unrelated to having two cylinders intersect, as long as they're parallel.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!