MATLAB QUESTION Suppose the weekly hours for all employees are stored in a text
ID: 3815203 • Letter: M
Question
MATLAB QUESTION
Suppose the weekly hours for all employees are stored in a text file where each line contains the employee name followed by the hours worked for each day of the week. The data is stored as follows (data is continuous in the file but represented in columns below): (write a MATLAB script)
John Doe 2 4 3 4 5 8 8
Jane Smith 7 3 4 3 3 4 4
Joe Hart 3 3 4 3 3 2 2
Katie Jones 9 3 4 7 3 4 1
Michael Hu 3 5 4 3 6 3 8
Emily Wright 3 4 4 6 3 4 4
Jim Young 3 7 4 8 3 8 4
Kelly Green 6 3 5 9 2 7 9
Brian Hurley 4 9 8 3 3 2 5
Write a program that reads the contents from the file weeklyHours.txt, and outputs the name of the employee and the average number of hours worked that week.
Input Data : Contents read from weeklyHours.txt ; Name followed by 7 numbers (hours worked for the 7 days of the week)
Output Data : Name ; Average hours for the week
What I have so far:
fh = fopen('weeklyHours.txt','r');
while ~feof(fh)
total = 0;
j=....;
for i = 1:8
> if i==1
employeeHours{j}=...;
else
total = total+.....;
end
end
j = ....;
employeeHours{j} = total ./ 7;
end
I would greatly appreciate some help for finishing this script. Specifically what the j's should be equal to, and what the total should be equal to. Where the periods (....) are, that shows where I am stuck at, meaning I don't know what to put in place of the periods.
Thanks for the help.
*note: the text file is simply what the output is. i.e. John Doe 2 4 3 4 5 8 8 Jane Smith 7 3 4 3 3 4 4 Joe Hart 3 3 4 3 3 2 2 Katie Jones 9 3 4 7 3 4 1 Michael Hu 3 5 4 3 6 3 8 Emily Wright 3 4 4 6 3 4 4 Jim Young 3 7 4 8 3 8 4 Kelly Green 6 3 5 9 2 7 9 Brian Hurley 4 9 8 3 3 2 5
Explanation / Answer
/*You need to read in the first and last name, assuming that there are always just two names, followed by average no. of hours per day of the week*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.