Count number of points within each cell using scatteredInterpolant

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by