Suppose that this year November 23 is a Friday, what day of the week was Novembe
ID: 3936995 • Letter: S
Question
Suppose that this year November 23 is a Friday, what day of the week was November 5? Or November 21? One way to answer correctly is to answer the more general question: given that a particular day of a particular month is a particular day of the week, what day of the week is any other day of that same month? That will be your job for this portion of the assignment. Specifically, write a Mat lab function called celldate.m to accomplish this job. Your function should take two input parameters as follows: givenday, a 1 times 3 cell array with the following contents - 1st cell: a char value identifying the day of the week as 'S' (Sunday), 'M' (Monday). 'T' (Tuesday), 'W' (Wednesday), 'R' (Thursday), 'F' (Friday), or 'A' (Saturday) - 2nd cell: an integer from 1 to 12 representing the month (with the correspondence January doubleheadarrow 1, February doubleheadarrow 2, and so on ...) - 3rd cell: the date of the given day in the month as an integer from 1 to n, where n is the number of days in the month otherday, an integer representing a different date in the same month The output of the function should be a cell array called cellout, with the same format as the Input parameter givenday, but with specific values customized for the alternate date of the same month given in otherday. For example, to answer the initial question posed in this problem, one could define C={'W', 11, 23), then call the function as celldate(C, 5), and the output should be the cell array {'A', 11, 5}. Similarly, if D={'R', 4, 5}, then the function call celldate(D, 23) should have the cell array {'M', 4, 23) as its output. For simplicity, yon may avoid considering leap years...i.e., for this problem you may assume February will always have days.Explanation / Answer
MATLAB FUNCTION
function [ cellout ] = celldate( givenday,otherday )
% The week symbol vector
week = ['S','M','T','W','R','F','A'];
% Find the index of the given week
for i = 1:7
if(givenday{1} == week(i))
K = i;
end
end
% Calculate the day of the week of otherday
var = mod(K+mod(otherday,7)-mod(givenday{3},7),7);
if var == 0
var = 7;
end
cellout = { week(var), givenday{2}, otherday };
% Creating the cell vector with month and date
end
SAMPLE RUNNING OF THE PROGRAM
>> celldate({'W',11,23},5)
ans =
'A' [11] [5]
>> celldate({'R',4,5},23)
ans =
'M' [4] [23]
>>
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.