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!

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top