find関数について
6 ビュー (過去 30 日間)
古いコメントを表示
pix = 0.001;
a = -1:pix:1;
find(a==0.1)
配列aには0.1が格納されているにもかかわらず,findでインデックスを得ることができません.
ほかに要素のインデックスを得る方法がありましたら教えていただけると幸いです.
0 件のコメント
回答 (1 件)
Dyuman Joshi
2024 年 2 月 16 日
編集済み: Dyuman Joshi
2024 年 2 月 16 日
Welcome to the world of floating point numbers, where not all numbers can be represented exactly in binary form.
See this thread for more information - https://in.mathworks.com/matlabcentral/answers/57444-why-is-0-3-0-2-0-1-not-equal-to-zero?s_tid=faqs_link
When comparing floating point numbers, the best practice is to use a tolerance -
pix = 0.001;
a = -1:pix:1;
tol = 1e-6;
idx = find(abs(a - pix) < tol)
%check
a(idx)
k = ismembertol(a, pix);
IDX = find(k)
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!