find関数について
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
pix = 0.001;
a = -1:pix:1;
find(a==0.1)
配列aには0.1が格納されているにもかかわらず,findでインデックスを得ることができません.
ほかに要素のインデックスを得る方法がありましたら教えていただけると幸いです.
0 Kommentare
Antworten (1)
Dyuman Joshi
am 16 Feb. 2024
Bearbeitet: Dyuman Joshi
am 16 Feb. 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 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!