MATLAB Write a function called June2015 that returns a cell array of dimensions
ID: 3767208 • Letter: M
Question
MATLAB
Write a function called June2015 that returns a cell array of dimensions 30-by-3, whose rows correspond to the days of June, 2015. The three elements of each row must be set as follows:
· The first element refers to the string 'June' (uppercase ‘J’).
· The second element refers to a scalar of type double that equals the date (1 through 30).
· The third element refers to 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 cell array that is returned by the function:
>> m = June2015;
>> m(11,:)
ans =
'June' [11] 'Thu'
Explanation / Answer
MATLAB Code:
Sample output:
Code to Copy:
function A = June2015
%declar cell array of 30 by 3
A=cell(30,3);
for i = 1:30
d=datenum([2015, 6, i]);
[DateNumber, DateName] = weekday(d);
A(i,:)={'June', i, DateName}
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.