필터 지우기
필터 지우기

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 CenterFile Exchange에서 Introduction 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