Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(A) In MATLAB, write a function dayName that consumes a parameter, day , contain

ID: 3554118 • Letter: #

Question

(A)   In MATLAB, write a function dayName that consumes a parameter, day, containing the numerical value of a day in the month of March 2014.


For example: dayName(8) should return Saturday.


(B) You are now given a variable named days, a vector that contains the numeric values of days in the month of March 2014. Write a script that will convert each numeric value on the vector days into a string named daysOfWeek with the day names separated by a comma and a space.


For example: if days=[8, 9, 10] then daysOfWeek=Saturday, Sunday, Monday


Explanation / Answer

A.)


function day=dayName(daynumber)

dayarray=cellstr(['Saturday';'Sunday';'Monday';'Tuesday';'Wednesday';'Thursday';'Friday']);

day=dayarray{mod(daynumber,7)};


B.)


days=[8, 9, 10];

daysOfWeek='';

flag=0;

for i = days

if flag==0

daysOfWeek=strcat(daysOfWeek,dayName(i));

flag=1;

else

daysOfWeek=strcat(daysOfWeek,',',dayName(i));

end

end

daysOfWeek