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
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:9.10
All Answers
total answers (1)
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