Question

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!

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top