I wonder if there is a faster solution to the problem below than using loops.
I have a set of points scattered in 3D space, with a value assigned to each point. So something like dataPoints = [x1, y1, z1, v1; x2, y2, z2, v2; ...]
dataPoints = [x1, y1, z1, v1; x2, y2, z2, v2; ...]
dataPoints = [x1, y1, z1, v1; x2, y2, z2, v2; ...]
. The 3D space is evenly split into subvolumes dx
× dy
× dz
. I need to create a matrix containing the sum of v
's in each subvolume.
The number of subvolumes and data points can be pretty big, on the order of 1 million each. So loops are really to be avoided.
I can easily find out, which subvolume a point belongs to:
ix(:) = floor(x(:) / dx) + 1;
iy(:) = floor(y(:) / dy) + 1;
iy(:) = floor(z(:) / dz) + 1;
However now I need to add up all points with the same tuple (ix, iy, iz)
. Any ideas?
sums = accumarray( { iy(:), ix(:), iz(:) }, v(:) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.