Counting number of individuals between a box

1 view (last 30 days)
Hello,
I have 7000 particles scattered in an area. I would like to count the number of them in one particular area delimited by fixed coordinates. For example:
Particles number Coordinates X Coordinates Y
1 25 58
2 18 30
3 5 45
4 26 60
5 27 61
6 14 70
How many particles are located in the area: 20<x<30 and 57<y<71? The aswer should be: 3
Thank you for your help.
Jonathan

Answers (1)

Star Strider
Star Strider on 27 Jul 2020
Try this:
A = [1 25 58
2 18 30
3 5 45
4 26 60
5 27 61
6 14 70];
Count = nnz(A(:,2)>20 & A(:,2)<30 & A(:,3)>57 & A(:,3)<71)
producing:
Count =
3
.

Categories

Find more on Animation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!