I've written this section of code:
for k=0.05:0.05:38
index=find(A(:,2)==k);
c=max(A(index,1));
end
but for k=37.7, it returns index as a 0x1 empty double column vector. For all other values of k it works. However, when I simply do:
index=find(A(:,2)==37.7);
it returns a number. Any ideas why the loop won't? Thanks

 採用された回答

KSSV
KSSV 2022 年 6 月 14 日

0 投票

tol = 10^-3 ;
index=find(abs(A(:,2)-37.7)<tol);
Read about comparing floating point numbers.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2022 年 6 月 14 日

コメント済み:

2022 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by