Counting number of individuals between a box

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

回答(1 个)

Star Strider
Star Strider 2020-7-27
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
.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by