How to use Floor command
Show older comments
I have some wrong thing with floor command. This problem is that
Step 1: Initial step
t=[0.90 1.00 1.30 1.80 1.90];
step = (t(5)-t(1))/100;
time = t(1):step:10;
Step 2: Check floor command
time(181)
ans =
2.7000
floor((time(181)-0.9)/(2*0.9))
ans =
0
*But i realize that*
floor((2.7-0.9)/(2*0.9))
ans =
1
What problem was happen in this case?
Question 2: Logic condition
t_ = 4.5 - 4*0.9
t_ =
0.9000
t_ >= 0.9
ans =
0
But
0.9>=0.9
ans =
1
Accepted Answer
More Answers (3)
You're not accounting for floating point errors.
4.5 - 4*0.9
will not give you precisely 9/10, but rather something accurate to many decimal places.
Honglei Chen
on 4 Oct 2012
0 votes
This has nothing to do with floor, it's part of the floating point computation. See the link below
trung trinh
on 4 Oct 2012
0 votes
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!