Effacer les filtres
Effacer les filtres

find関数について

6 vues (au cours des 30 derniers jours)
結衣菜
結衣菜 le 16 Fév 2024
Modifié(e) : Dyuman Joshi le 16 Fév 2024
pix = 0.001;
a = -1:pix:1;
find(a==0.1)
ans = 1×0 empty double row vector
配列aには0.1が格納されているにもかかわらず,findでインデックスを得ることができません.
ほかに要素のインデックスを得る方法がありましたら教えていただけると幸いです.

Réponses (1)

Dyuman Joshi
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.
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)
idx = 1002
%check
a(idx)
ans = 0.0010
You can also use ismembertol -
k = ismembertol(a, pix);
IDX = find(k)
IDX = 1002

Catégories

En savoir plus sur 起動と終了 dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!