Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Tyler Danzig
Tyler Danzig am 1 Dez. 2021
Beantwortet: Voss am 1 Dez. 2021
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?

Akzeptierte Antwort

Voss
Voss am 1 Dez. 2021
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));

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by