[英]3D binning in Matlab
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. 我有一组散布在3D空间中的点,每个点都有一个值。 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; ...]
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
. 将3D空间均匀地分成子体积
dx
× dy
× dz
。 I need to create a matrix containing the sum of v
's in each subvolume. 我需要创建一个矩阵,其中包含每个子体积中
v
的总和。
The number of subvolumes and data points can be pretty big, on the order of 1 million each. 子体积和数据点的数量可以非常大,每个数量级为100万。 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)
. 但是现在我需要用相同的元组
(ix, iy, iz)
来加起所有点。 Any ideas? 有任何想法吗?
sums = accumarray( { iy(:), ix(:), iz(:) }, v(:) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.