13 Write a user-defined MATLAB function that determines the time elapsed between two events during a day.
Question:
13 Write a user-defined MATLAB function that determines the time elapsed between two events during a day. For the function name and arguments, use dt = timediff(TA,ap1,TB,ap2). The input arguments to the function are:
TA is a two-element vector with the time of the first event. The first element is the hour and the second element is the minute.
ap1 is a string ‘AM’ or ‘PM’ which corresponds to the time of the first event.
TB is a two-element vector with the time of the second event. The first element is the hour and the second element is the minute.
ap2 is a string ‘AM’ or ‘PM’ which corresponds to the time of the second event.
The output argument dt is a two-element vector with the time elapsed between two events. The first element is the number of hours and the second element is number of minutes.
The function displays an error message if the time entered for event B is before the time entered for event A.
Use the function to determine the time elapsed between the following events:
(a) Event A: 5:37 AM; Event B: 2:51 PM.
(b) Event A: 12:53 PM; Event B: 6:12 PM.
(c) Event A: 11:32 PM; Event B: 3:18 PM. (Error situation.)
Step by Step Answer: