フィルターのクリア

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

2 ビュー (過去 30 日間)
Tim Fulcher
Tim Fulcher 2022 年 3 月 2 日
コメント済み: Tim Fulcher 2022 年 3 月 2 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by