2014-09-22 38 views
0

我有点根据某个点过程分布在一个正方形上,可能是泊松点过程。我想将广场分成更小的广场,并计算每个广场的点数。是否有一种简单的方法可以通过内置函数在Matlab中完成?计算几个子区域中每个点的点数

+1

它可以在几行来替换最后一个命令。你如何定义边缘?请编辑您的答案,以小数字示例定义您的数据变量。 – 2014-09-22 15:30:50

+0

查看类似:See [this](http://stackoverflow.com/questions/18639518/generate-and-plot-the-empirical-joint-pdf-and-cdf)answer – 2014-09-22 15:31:39

+1

这听起来像是一个二维直方图,这可以通过''accumarray()''非常有效地完成。编辑:看到Amro的这个答案:http://stackoverflow.com/questions/6777609/fast-2dimensional-histograming-in-matlab编辑:另见''hist3()'' – Nras 2014-09-22 15:33:34

回答

0

正如Nras所说,内置命令hist3完全符合你的要求。为了证明它的使用,我生成了极点半径和极角均匀分布的点:

n = 100000; 
r = rand(n,1); 
theta = 2*pi*rand(n,1); 
points = [r.*cos(theta), r.*sin(theta)]; 
hist3(points,[15,15]); % [15,15] is the number of bins in each direction 

图形输出如下。如果你想实际计数,而不是一幅画,用

counts = hist3(points,[15,15]); 

hist3