Count number of points within each cell using scatteredInterpolant

3 views (last 30 days)
Hello
I have an mx3 array of points in XYZ format. I'm using scatteredInterpolant in order to convert these points into a 2D array (image). I first use meshgrid to create a rectangular grid of X and Y values, e.g.:
[XGrid,YGrid] = meshgrid(x,y); % x and y are linearly spaced vectors based on the desired cell size, created using the raw xyz data
F = scatteredInterpolant(x_raw,y_raw,z_raw,'natural');
ZGrid = F(XGrid,YGrid);
For my work it would be very useful to find the number of points from the raw data which fall into each element (pixel) of the resulting image (2D array). In the above code, x and y are linearly spaced vectors obtained from irregularly spaced raw data (x_raw,y_raw,z_raw).
Any help would be greatly appreciated,
Jack Williams

Accepted Answer

Steven Lord
Steven Lord on 4 Apr 2016
If you're using release R2015b or later, take a look at the histcounts2 and histogram2 functions.
  1 Comment
Jack Williams
Jack Williams on 4 Apr 2016
Steven,
Thanks very much for this. In relation to the problem above
N = histcounts2(x_raw,y_raw,x,y);
worked perfectly, where x and y are the edges of the bins.
Cheers,
Jack

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!