Find function for Matrix

2 ビュー (過去 30 日間)
Jonathan Moorman
Jonathan Moorman 2020 年 8 月 20 日
コメント済み: Jonathan Moorman 2020 年 8 月 20 日
Hi! I'm trying to use the find function for the first time in my code and have come across a problem. It appears that in about half my runs, the function is unable to find the value in the matrix when it is clearly there. Has anyone seen this error before or am I doing something incorrect in the code?
Below is three screenshots of the value it should be looking for (0.1573), in the matrix (a90Export6dB), and I am getting a empty vector when the value is clearly there.
Figure 1:
Figure 2:
Figure 3:

採用された回答

KSSV
KSSV 2020 年 8 月 20 日
編集済み: KSSV 2020 年 8 月 20 日
When you are comapring a floating point number you should not use ==, you should fix some tolerance and use inqualitty. Check the below example code:
tol = 10^-5 ;
val = rand ;
A = rand(1,10) ;
A(5) = val ; % replace this index with vl to seek later
idx = abs(A-val)<=tol ; % logical indices
id = find(idx) % index
  1 件のコメント
Jonathan Moorman
Jonathan Moorman 2020 年 8 月 20 日
Worked great!. Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by