Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!