필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 3월 2일
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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by