MATLAB: How to generate n cubes to define a sphere

cubed sphere

I would like to generate cubes in a sphere. For example I would like to start simple where I can generate a central cube with 26 surrounding cubes that fit in a sphere defined by the size of the cubes. I am not concerned about filling the sphere completely. This would be my first attempt where I have to find the center of the surrounding cubes with respect to the center cube. Once I get my program working where I perform a calculation on the surrounding 26 cubes I would like to extend it to many cubes where I can record the center of each cube. So my program will subtend n cubes surrounding a central cube.
I would like to plot the 27 cubes and record the central (x,y,z) of each cube. I have tried using some examples but they are far move involved than I need. I appreciate the help.
Chad

Best Answer

To create the cubes and visualize them I would start with something like the following:
It has proven useful in the past but requires the use of patches, if you are not familiar with them I suggest looking in the help