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

Write a function called year2016 that returns a row-vector of struct-s whose ele

ID: 3847139 • Letter: W

Question

Write a function called year2016 that returns a row-vector of struct-s whose elements
correspond to the days of a month in 2016 as specified by the input argument. If the input is
not an integer between 1 and 12, the function returns the empty array. Each struct should
contain three fields with these (exact) field names: “month”, “date”, and “day” (all lower case).
The month field must contain a string with the name of the month (first letter capitalized).
The date field must contain a scalar specifying the day of the month.
The day field must contain the three-letter abbreviation of the day chosen from this list:
'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'.
For example, here is a call of the function followed by a command that shows the seventh
element of the struct array that is returned by the function:
>> m = year2016(2);
>> m(7)
ans =
month: 'February'
date: 7
day: 'Sun'

my code is

function out = year2016(m)
VN = datenum([2016,m,1]):datenum([2016,m+1,1])-1;
DN = 1+mod(VN-3,7);
MC = {'January';'February';'March';'April';'May';'June';'July';'August';'September';'October';'November';'December'};
DC = {'Mon','Tue','Wed','Thu','Fri','Sat','Sun'};
out = struct('day',DC(DN),'date',num2cell(1:numel(VN)));
[out(:).month] = deal(MC{m});
end

what is problem?

Explanation / Answer

Hi,

The below code works fine. Let us know where you are getting the error.

I have tried this and its working fine. Find the sample output as well.

function out = year2016(m)
VN = datenum([2016,m,1]):datenum([2016,m+1,1])-1;
DN = 1+mod(VN-3,7);
MC = {'January';'February';'March';'April';'May';'June';'July';'August';'September';'October';'November';'December'};
DC = {'Mon','Tue','Wed','Thu','Fri','Sat','Sun'};
out = struct('day',DC(DN),'date',num2cell(1:numel(VN)));
[out(:).month] = deal(MC{m});
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote