Вопрос

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