find関数について
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
pix = 0.001;
a = -1:pix:1;
find(a==0.1)
配列aには0.1が格納されているにもかかわらず,findでインデックスを得ることができません.
ほかに要素のインデックスを得る方法がありましたら教えていただけると幸いです.
0 commentaires
Réponses (1)
Dyuman Joshi
le 16 Fév 2024
Modifié(e) : Dyuman Joshi
le 16 Fév 2024
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 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!