The find function does not find the attribute element and outputs an empty row vector. What's the reason?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
sangjun han
am 28 Mai 2021
Kommentiert: Stephen23
am 28 Mai 2021
Here's my code.
for example,
V_bg=0.6:1/100:1.2;
output=find(V_bg==0.9);
i want to find value 0.9 but the ans is just 1x0 empty double row vector ?
i don't why
1 Kommentar
Stephen23
am 28 Mai 2021
"What's the reason?"
Because you are testing for exact equivalence of values which are not exactly the same.
Read more about binary floating point numbers:
This is worth reading as well:
Akzeptierte Antwort
Asmit Singh
am 28 Mai 2021
To find a noninteger value using the find function, it is recommended to use a tolerance value based on your data. Otherwise, the result is sometimes an empty matrix due to floating-point roundoff error. You can have look at the documentation for further details.
V_bg=0.6:1/100:1.2;
% change the tolerance level according to your liking
output=find(abs(V_bg-0.9)<0.001);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!