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'
I have been trying for hourse. I am not sure how to make it so, that when i call the function afther that i have the option to write m again but this time give it a value and to become the day at the end. I would be really gratefull. It should look like this :
m = year2016(4)m = 1×30 struct array with fields: month date day>> m(1)ans = struct with fields: month: 'April' date: 1 day: 'Fri'
and myone one looks like this:
m = year2016(1)
m =
struct with fields: month: 'January' day: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31]
Here is my code now, i have changed it more than 10 times so it doesnt really show my closest attempt probably, but would give some idea why i am not doing it right.
function [m] = year2016( x ) field1 = 'month'; field2 = 'date'; field3 = 'day'; m1 = 'January'; m2 = 'February'; m3 = 'March'; m4 = 'April'; m5 = 'May'; m6 = 'June'; m7 = 'July'; m8 = 'Augustm'; m9 = 'September'; m10 = 'October'; m11 = 'November'; m12 = 'December';d1 = {1,2,3}; d2 = [1:30]; d3 = [1;2;3];m = struct(field1,m1,field2,d3);%,m2,d1,m3,d3,m4,d2,m5,d3);
end
Best Answer