Sorting coordinates on radial distance from origin

3 vues (au cours des 30 derniers jours)
George Vaisey
George Vaisey le 9 Juin 2022
Commenté : George Vaisey le 9 Juin 2022
Very new to MatLab and struggling with what I think is probably very easy.
I have a set of x,y coordinates over time from particle tracking analysis. I would like to set the origin to a specific x,y coordinate and then calculate the number of coordinates that are some given radial distance from this origin.
Any help greatly appreciated!

Réponse acceptée

Torsten
Torsten le 9 Juin 2022
If (x0,y0) is the reference point and your coordinates are saved in a matrix XY of size (2xn), then just use
R = 2.0; %e.g.
n = numel(find((XY(1,:)-x0).^2+(XY(2,:)-y0).^2 <= R^2))
n is the number of points in the XY matrix that lie within a radial distance of R from (x0,y0).
  2 commentaires
James Tursa
James Tursa le 9 Juin 2022
Or just replace numel(find(... with sum(... or nnz(...
George Vaisey
George Vaisey le 9 Juin 2022
Worked great, cheers!

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 9 Juin 2022
Modifié(e) : James Tursa le 9 Juin 2022
Here's one way to do that:
[~,distance] = cart2pol(x-x0,y-y0); %distances from (x0,y0)
count = nnz(dist_Lower<=distance & distance<=dist_Upper) % count the number within a certain distance range

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by