A few more test cases would be nice.
Most of the solutions seem to complicate the calculation to artificially compensate for the fact that the test problem result is in error by 0.01.
Re: the value in the single test case, it's possible that you're supposed to truncate at two decimal digits as well. Which actually makes me wish MATLAB had something like floor(x, 2) and ceil(x, 2), akin to round(x, 2).
Getting logical indexes
Getting the indices from a vector
Replicate elements in vectors
Find the logic
Find the treasures in MATLAB Central and discover how the community can help you!
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office