How to determine which points in an array are with a ring? Stupid question.

5 vues (au cours des 30 derniers jours)
Hi All,
I have an arrays of equal length consisting of x position, y position and energy. I wish to determine which of those entries fall within a ring without resorting to doing it iteratively.
Code (which doesn't work) is:
distances = sqrt(X_Position.^2 + Y_Position.^2);
if (distances > Inner_Radius) & (distances < Outer_Radius)
X_Position_on_Instrument = X_Position;
Y_Position_on_Instrument = Y_Position;
Energy_on_Instrument = Energy;
end
In other words the new arrays (on_Instrument) will only contain values which fall within the ring. I know the answer will be really simple but I can't see it at the mo'.
Thanks again.
Regards
Tim

Réponse acceptée

Cris LaPierre
Cris LaPierre le 2 Mar 2022
Use logical indexing.
distances = sqrt(X_Position.^2 + Y_Position.^2);
% create logical index to indicate points that meet condition
ind = distances>Inner_Radius & distances<Outer_Radius;
% Use that index to extract the corresponding data
X_Position_on_Instrument = X_Position(ind);
Y_Position_on_Instrument = Y_Position(ind);
Energy_on_Instrument = Energy(ind);

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by