Counting number of individuals between a box

1 visualización (últimos 30 días)
Jonathan Demmer
Jonathan Demmer el 27 de Jul. de 2020
Respondida: Star Strider el 27 de Jul. de 2020
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

Respuestas (1)

Star Strider
Star Strider el 27 de Jul. de 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
.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by