Develop a mfile function to determine the elapsed seconds in

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, min, sec) where: day = the day of the week (1 for Sunday, 2 for Monday, etc.) hour = the hour of the day (in 24 hour format) min = the minute of the hour sec = the seconds of the hour Please turn in a hardcopy of your script file at the beginning of class. Also email me the script file with a subject heading of \"ME224 Assignment 4_\'Your last name\"\'.

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site