Problem 56288. Angle Between Analog Clock Hands
Given a datetime variable t, return the angle (in degrees) between the hour and minute hands of an analog clock at the time represented by t.
- The angle returned should be the smaller of the two angles between the hands (ie it should always be in the range [0,180]).
- Assume the hands are moving continuously (so at 03:30:00, the hour hand will be halfway between 3 and 4; at 03:26:30, the minute hand will be halfway between 26 and 27, etc).
- The time may be am or pm; the angle returned should be assuming a standard 12-hour clock (so 03:26:30 and 15:26:30 will return the same angle).
Solution Stats
Problem Comments
-
3 Comments
goc3
on 29 Oct 2022
The solution template had "function " twice (i.e., "function function angle = ...). That has been fixed.
GeeTwo
on 6 Dec 2022
Wow! No one else thought to start by converting the datetime to a scalar?
Jean-Marie Sainthillier
on 4 Jan 2023
Good problem.
Very interesting, various and pleasant problem group.
Solution Comments
Show commentsProblem Recent Solvers111
Suggested Problems
-
Remove all the words that end with "ain"
2627 Solvers
-
Find the largest value in the 3D matrix
1657 Solvers
-
Getting the indices from a vector
11727 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
448 Solvers
-
How long do each of the stages of the rocket take to burn?
445 Solvers
More from this Author33
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!