How can i count the number of point in each grid?

8 views (last 30 days)
I have a randomly generated scatter of 5000 points and I have laid a ring grid over the scatter plot.
Could somebody help me in calculating the number of points in the grid.
I did try to use histcounts2 but that was not giving me the correct answer.
Attached is a sample image in which I am trying to find the number of points in each grid.

Answers (1)

KSSV
KSSV on 21 Jan 2021
Get each box coordinates, this box is a polygon and then use the function inpolygon. Run a loop for each box.
  2 Comments
Vamsi Krishna Vempati
Vamsi Krishna Vempati on 21 Jan 2021
Hi,
Thank you for the answer. But I am trying to calculate the total number of points within those coordinates and not if a certain point is inside the polygon or outside of it.
KSSV
KSSV on 22 Jan 2021
Won't you think if you know whether points are inside the polygon, you can count the points? Inpolygon gives you the indices of points lying inside the polygon you can count the indices and the count says how many points are they.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!