ImageAnalyst <imageanalyst@mailinator.com> wrote in message <dba81928387f46d6a867e5d56468d3c8@g23g2000yqh.googlegroups.com>...
> On Nov 18, 7:29?pm, "Eli " <elech...@ryerson.ca> wrote:
> > Dear Matlab users,
> > I am trying to write a program that could efficiently determine which voxel a point in space lies inside.
> > Supposing I have a 3 dimensional cube in space, that is segmented into n^3 smaller voxels. Each of these voxels will have an index ranging from 1:n^3 and each voxel centre can be determined easily.
> > No suppose I take p number of random points with coordinates (Xp,Yp,Zp) located somewhere inside the big cube.
> > I would really appreciate suggestions to writing a very efficient code to determine which voxel index each of these points lie inside.
> > At this point I have an array Mapper, with dimensions (n^3,3) indicating the centre of each small voxel.
> > Thanks very much,
> > Eli
>
> 
> You need to use the sub2ind() function. For example:
>
> workspace; % Show the Workspace panel.
> voxels = zeros(3,4,5) % Create a 3D array  I don't care what values
> it has.
> % Find index of voxel at (x,y,z) = (1,1,1).
> index1 = sub2ind(size(voxels), 1,1,1)
> % Find index of voxel at (x,y,z) = (1,2,4).
> index2 = sub2ind(size(voxels), 1,2,4)
> % Find index of voxel at (x,y,z) = (3,4,5).
> index3 = sub2ind(size(voxels), 3,4,5)
thanks for the help, but I think you misunderstood my problem.
I am able to index the voxels. but suppose I choose a random point (x,y,z), which will not in general have integer values, and will not in general lie in the centre of the voxel. I wish to find which voxel this point falls in. What I am doing now. is calculating the difference between my point and the centres of all voxels, and then finding the minimum distance, however, this is quite computationally heavy. Is there a faster way to determine in which voxel index my point falls?
Eli
