Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Cris LaPierre
Cris LaPierre il 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);

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by