Search Program on this blog

Thursday 20 August 2015

Write a function called May2015 that returns a struct vector (row or column) whose elements correspond to the days of May, 2015. Each struct should contain three fields with these (exact) field names: “month”, “date”, and “day” (all lower case).  The month field must contain the string 'May' (uppercase ‘M’).  The date field must contain a scalar of type double that equals the date (1 through 31).  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 eleventh element of the struct array that is returned by the function: >> m = May2015; >> m(11) ans = month: 'May' date: 11 day: 'Mon'

function m = May2015
%Output m is struct vector
%Example: m = May2015
%         m(11)
D={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};
M={'Fri','Sat','Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue','Wed','Thu',
   'Fri','Sat','Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue','Wed','Thu',
   'Fri','Sat','Sun'};
m=struct('month','May','date',D,'day',M);

No comments:

Post a Comment