1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} dateaxis ()
18 ## @deftypefnx {Function File} {} dateaxis (@var{ax})
19 ## @deftypefnx {Function File} {} dateaxis (@var{ax}, @var{dateform})
20 ## @deftypefnx {Function File} {} dateaxis (@var{ax}, @var{dateform}, @var{startdate})
21 ## @deftypefnx {Function File} {} dateaxis (@var{h}, ...)
23 ## Convert the current axis tick labels (or the axis handle @var{h}) to
24 ## a date format. The axis given by @var{ax} ("x", "y", or "z") will be
25 ## changed; the default is "x". The date format, @var{dateform}, used
26 ## will be either auto-determined or an integer corresponding to the
27 ## date formats in datestr. If @var{startdate} is given, then the first
28 ## tick value on the given axis is assumed to be that date.
30 ## @seealso{bolling, candle, highlow, movavg, pointfig}
33 function dateaxis (varargin)
43 if ishandle(varargin{1})
47 if length(varargin) > 0
50 if length(varargin) > 1
51 dateform = varargin{2};
53 if length(varargin) > 2
54 startdate = varargin{3};
56 startdate = datenum(startdate);
57 elseif !isnumeric(startdate)
58 error ("dateaxis: startdate must be either a datenum or numeric")
61 if length(varargin) > 3
71 r = range(get(h, [ax "lim"]));
73 ## minutes and seconds
93 ticks = get (h, [ax "tick"]);
94 if (!isempty (startdate))
95 ticks = ticks - ticks(1) + startdate;
97 ticks = datestr(ticks, dateform);
98 ticks = mat2cell(ticks, ones(size(ticks,1),1), size(ticks,2));
99 set (h, [ax "ticklabel"], ticks);