cannot find existing number

1 Ansicht (letzte 30 Tage)
Luis Eduardo Cofré Lizama
Kommentiert: Star Strider am 8 Jan. 2023
I have the following data where fs =100;
tstamp =(1/fs:1/fs:12000*(1/fs))
Then when looking for the value 117 (find(tstamp == 117)), the results is [], however, the value does exist though with a trail of zeros (117.0000), is that the prob? how to solve?
Please help with this very likely simple prob.
cheers
Eduardo

Akzeptierte Antwort

Star Strider
Star Strider am 8 Jan. 2023
See the documentation section on Floating-Point Numbers for a full explanation.
Actually, I can’t reproduce that exact problem, since it works correctly here —
format long
fs =100;
tstamp =(1/fs:1/fs:12000*(1/fs))
tstamp = 1×12000
0.010000000000000 0.020000000000000 0.030000000000000 0.040000000000000 0.050000000000000 0.060000000000000 0.070000000000000 0.080000000000000 0.090000000000000 0.100000000000000 0.110000000000000 0.120000000000000 0.130000000000000 0.140000000000000 0.150000000000000 0.160000000000000 0.170000000000000 0.180000000000000 0.190000000000000 0.200000000000000 0.210000000000000 0.220000000000000 0.230000000000000 0.240000000000000 0.250000000000000 0.260000000000000 0.270000000000000 0.280000000000000 0.290000000000000 0.300000000000000
v = find(tstamp == 117)
v =
11700
D = v - 11700
D =
0
I was hoping to be able to demonstrate floating-point approximation error.
Oh well ...
.
  3 Kommentare
Walter Roberson
Walter Roberson am 8 Jan. 2023
There are various fairly obscure ways in which the floating point round-off algorithm can end up being changed. That does not happen often, but it can happen.
Star Strider
Star Strider am 8 Jan. 2023
@Luis Eduardo Cofré Lizama — As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 8 Jan. 2023

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by