|
"mahdi roozbhani" <m.m.roozbahani@gmail.com> wrote in message <jnhs4e$lg8$1@newscl01ah.mathworks.com>...
> I dont know why I did many mistakes to write this little code. Here hopefully is the correct one. Pl help me with that?
>
> sphere_voxel = [];
> e = 20;
> r = 1;
> t = linspace(-r,+r,e);
> for i = 1:e
> for j = 1:e
> for k= 1:e
> if (t(i))^2 + (t(j))^2 + (t(k))^2 <= r^2
> lp = length(sphere_voxel);
> sphere_voxel(e+lp,:) = [t(i) t(j) t(k)];
> end
> end
> end
> end
- - - - - - - - - - - -
[TK,TJ,TI] = ndgrid(linspace(-r,+r,e));
S = TI.^2+TJ.^2+TK.^2<=r^2;
sphere_voxel = [TI(S),TJ(S),TK(S)];
Roger Stafford
|