-1

I have a cube of 20*20*20 cm^3 and voxels of 1cm^3, how do I get the coordinates of all the 20*20*20=8000 voxel centers as a list of [x,y,z] (size 8000*3)? Preferably in vectorized form! Thanks a lot!

adrelino
  • 160
  • 2
  • 10
  • What do you mean by "coordinates"? Can you give an example in a small case, say 2x2x2? – Luis Mendo Apr 09 '14 at 15:43
  • For 2*2*2 I need [ (0.5,0.5,0.5), (0.5,0.5,1.5), (0.5,1.5,0.5), (0.5,1.5,1.5), (1.5,0.5,0.5), (1.5,0.5,1.5), (1.5,1.5,0.5), (1.5,1.5,1.5) ] – adrelino Apr 10 '14 at 21:08

1 Answers1

1

ndgrid does the job:

N = 20;
[z, y, x] = ndgrid(.5:N); %// note reverse order to get desired order of result
xyz = [x(:) y(:) z(:)]; %// desired result
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147