function [d,w] = weekday(t)
%WEEKDAY Day of week.
%   [D,W] = WEEKDAY(T) returns the day of the week in numeric and 
%   string form given T, a serial date number or a date string.  
%   The days of the week are assigned the following values.
%
%                       1     Sun
%                       2     Mon
%                       3     Tue
%                       4     Wed
%                       5     Thu
%                       6     Fri
%                       7     Sat
%
%   For example, [d,w] = weekday(728647) or [d,w] = weekday('19-Dec-1994')
%   returns d = 2 and w = Mon.
% 
%   See also EOMDAY, DATENUM, DATEVEC.
 
%   Author(s): C.F. Garvin, 2-23-95
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 1997/11/21 23:48:11 $

if nargin < 1
  error('Please enter T.')
end

if isstr(t)
  nd = datenum(t); 
else
  nd = t;
end

week = ['Sun';'Mon';'Tue';'Wed';'Thu';'Fri';'Sat'];

d = rem(fix(nd)-1,7); % Returns day of week number   
i = find(d <= 0);
d(i) = d(i)+7;          % Add 7 to -d values for proper indexing in week
w = week(d,:);        % Maps day of week number to string
