find関数について
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
pix = 0.001;
a = -1:pix:1;
find(a==0.1)
配列aには0.1が格納されているにもかかわらず,findでインデックスを得ることができません.
ほかに要素のインデックスを得る方法がありましたら教えていただけると幸いです.
0 comentarios
Respuestas (1)
Dyuman Joshi
el 16 de Feb. de 2024
Editada: Dyuman Joshi
el 16 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre ビッグ データの処理 en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!