フィルターのクリア

Find the index of a value which is a variable in an array

1 回表示 (過去 30 日間)
Tyler Danzig
Tyler Danzig 2021 年 12 月 1 日
回答済み: Voss 2021 年 12 月 1 日
I am trying to find the index of a value in an array which I used an equation to determine and saved as a variable. This is what I would like to happen, but I get an error:
azimuth_angle = 180 + atand(b/a); % The equation yields an azimuth_angle of 195, which is a value in the array azimuth_z.
azimuth_index = find(azimuth_z == azimuth_angle); % azimuth_index should give me 337, which is the index I want, but it only works when I replace azimuth_angle with the value it is (195).
Where azimuth_z is a 360x1 single and b and a are just values.
Is there a way to use find() with a variable? Or is there another function I need to use?

採用された回答

Voss
Voss 2021 年 12 月 1 日
Sounds like azimuth_angle is not exactly 195, but it's something very close to 195.
So instead of using find to find an exact match, you can find values very close to 195, e.g.:
azimuth_index = find(abs(azimuth_z - azimuth_angle) <= 10*eps(azimuth_angle));
Or you can use min to find the closest match regardless of how close it is to 195:
[~,azimuth_index] = min(abs(azimuth_z - azimuth_angle));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by