Q:

The built-in function date returns a string containing the day, month, and year. Write a function (using the date function) that will always return the current day

0

The built-in function date returns a string containing the day, month, and year. Write a function (using the date function) that will always return the current day. If the function call expects two output arguments, it will also return the month. If the function call expects three output arguments, it will also return the year

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

whatdate.m

function [day, varargout] = whatdate

% Returns the current day and possibly also the

% current month and year

% Format of call: whatdate or whatdate()

% Returns the day; if 2 output arguments are expected,

% also the month; if 3 expected, also the year

d = date;

% always returns the day

[day, rest] = strtok(d, '-');

if nargout > 1

 % return the month also

 [month, rest] = strtok(rest, '-');

 varargout{1} = month;

end

if nargout == 3

 % return the year also

 varargout{2} = rest(2:end);

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now