Count number of points within each cell using scatteredInterpolant

4 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2016-4-4
If you're using release R2015b or later, take a look at the histcounts2 and histogram2 functions.
  1 个评论
Jack Williams
Jack Williams 2016-4-4
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by