Develop a mfile function to determine the elapsed seconds in
Solution
The number of seconds elapsed is calculated by calculating the total mins elapsed *60 + total secs in current minute.
Now for calculation of number of minutes elapsed, total no. of hours elapsed*60 + total minutes in current hour
similarly, number of hours elapsed is total no. of days elapsed*24 + total hours in current day.
Thus for calculation ofo total no. of elapsed seconds, we have to start from converting days into hours then minutes and then seconds.
The MATLAB script for function file is as below:
function [numsec] = seconds(day,hour,min,sec)
%total hours elapsed is no. of day*24 + no. of current hours
numhr=day*24+hour;
%total mins elapsed is no. of hours calculated above*60 + no. of current mins
nummin=numhr*60+min;
%total seconds elapsed is no. of mins calculated above*60 + no. of current secs
numsec=nummin*60+sec;
end
![Develop a m-file function to determine the elapsed seconds in a week. The first line of the function should be setup as: function [numsec] = seconds (day, hour Develop a m-file function to determine the elapsed seconds in a week. The first line of the function should be setup as: function [numsec] = seconds (day, hour](/WebImages/6/develop-a-mfile-function-to-determine-the-elapsed-seconds-in-987302-1761507335-0.webp)