find the position of a value in a "Double-precision array"
4 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a 12904*1 double-precision array in matlab and would like to find the position of a value. For example, when I input "-10.1333", it returns "1", when I input "-10", it returns "5". I tried "find(time_samp==-10.1333)", it just returens "0×1 empty double column vector". Need some help, thank you.

1 件のコメント
Stephen23
2023 年 8 月 10 日
This is a completely expected result with binary floating point numbers:
This is worth reading as well:
Instead of incorrectly assuming exact equivalence of binary floating point numbers, compare the absolute difference against a tolerance:
tol = 1e-10; % you select this to suit your data
idx = abs(A-B)<tol;
回答 (1 件)
John D'Errico
2023 年 8 月 10 日
編集済み: John D'Errico
2023 年 8 月 10 日
-10.1333 the EXACT VALUE? NO. All you see is that number written with 4 digits after the decimal point. You need to learn to use a tolerance.
Seriously, is 0.3333 the exact value of 1/3? Of course not! In fact, there is no finite number of digits that will exactly represent that fraction, as a DECIMAL, or as a number stored in a binary form, as it is internally in MATLAB.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!