0

I have points distributed over a square according to some point process, probably Poisson point process. I want to divide the square into smaller squares and calculate the number of points in each sub-square. Is there an easy way to do it in Matlab by probably a built-in function?

mohamed
  • 29
  • 5
  • 1
    It can be done in a few lines. How do you define the edges? Please edit your answer to define your data variables with a small numeric example. – Luis Mendo Sep 22 '14 at 15:30
  • Ver similar: see [this](http://stackoverflow.com/questions/18639518/generate-and-plot-the-empirical-joint-pdf-and-cdf) answer – Luis Mendo Sep 22 '14 at 15:31
  • 1
    That sounds like a 2-dimensional histogram, which can be done very efficiently with ``accumarray()``. Edit: see this answer by Amro: http://stackoverflow.com/questions/6777609/fast-2dimensional-histograming-in-matlab Edit: see also ``hist3()`` – Nras Sep 22 '14 at 15:33

1 Answers1

0

As Nras said, the built-in command hist3 does exactly what you want. To demonstrate its use, I generated points with uniformly distributed polar radius and polar angle:

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

The graphic output is below. If you want the actual counts instead of a picture, replace the last command with

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

hist3