1 |
function dateaxis(theTickAxis, theDateFormat, theBias) |
---|
2 |
|
---|
3 |
% dateaxis -- Resizeable "datetick" function. |
---|
4 |
% dateaxis('theTickAxis', theDateFormat, theBias) converts |
---|
5 |
% the labels of 'theTickAxis' {'x' | 'y' | 'z'} to dates |
---|
6 |
% in theDateFormat (see "help datestr") and makes the |
---|
7 |
% affected axis resizeable. The Matlab "datenum" or |
---|
8 |
% "datestr" that corresponds to zero can be entered as |
---|
9 |
% theBias. More than one axis can be labeled with dates |
---|
10 |
% by stringing 'theTickAxis' codes together, as in 'xy'. |
---|
11 |
% The input defaults are 'x', 2, and 0, respectively. |
---|
12 |
% dateaxis('demo') demonstrates itself. |
---|
13 |
% |
---|
14 |
% Calls: none |
---|
15 |
|
---|
16 |
% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. |
---|
17 |
% All Rights Reserved. |
---|
18 |
% Disclosure without explicit written consent from the |
---|
19 |
% copyright owner does not constitute publication. |
---|
20 |
|
---|
21 |
% Version of 26-May-1998 11:03:32. |
---|
22 |
|
---|
23 |
if nargin < 1, theTickAxis = 'x'; end |
---|
24 |
|
---|
25 |
% Demonstration. |
---|
26 |
|
---|
27 |
if isequal(theTickAxis, 'demo') |
---|
28 |
help(mfilename) |
---|
29 |
theNow = now; |
---|
30 |
t = -50:10:50; |
---|
31 |
theTitle = 'Original'; theXLabel = 'x'; theYLabel = 'y'; |
---|
32 |
for i = 1:2 |
---|
33 |
subplot(2, 1, i) |
---|
34 |
plot([0 -50; 0 0], [-50 0; 0 0], 'r-', t, t, '-o') |
---|
35 |
axis(55 * [-1 1 -1 1]) |
---|
36 |
text(+5, 0, 'now') |
---|
37 |
title(theTitle), xlabel(theXLabel), ylabel(theYLabel) |
---|
38 |
theTitle = ['dateaxis(''x'', 2, now)']; |
---|
39 |
theXLabel = 'Date'; theYLabel = 'Day Number'; |
---|
40 |
end |
---|
41 |
set(gcf, 'Name', 'DateAxis Demo') |
---|
42 |
dateaxis('x', 2, theNow) |
---|
43 |
figure(gcf) |
---|
44 |
return |
---|
45 |
end |
---|
46 |
|
---|
47 |
% Defaults. |
---|
48 |
|
---|
49 |
if nargin < 2, theDateFormat = 2; end |
---|
50 |
if nargin < 3, theBias = 0; end |
---|
51 |
if isstr(theBias), theBias = datenum(theBias); end |
---|
52 |
|
---|
53 |
% Process each 'tick-axis' code. |
---|
54 |
|
---|
55 |
for k = 1:length(theTickAxis) |
---|
56 |
|
---|
57 |
% Revert to "auto" tick-labels temporarily. |
---|
58 |
|
---|
59 |
switch upper(theTickAxis(k)) |
---|
60 |
case {'X', 'Y', 'Z'} |
---|
61 |
set(gca, [theTickAxis(k) 'TickMode'], 'auto') |
---|
62 |
set(gca, [theTickAxis(k) 'TickLabelMode'], 'auto') |
---|
63 |
otherwise |
---|
64 |
help(mfilename) |
---|
65 |
error([' ## Unknown Tick-Axis Designation: ' theTickAxis(k) '.']); |
---|
66 |
end |
---|
67 |
|
---|
68 |
% Convert ticks to date-strings. |
---|
69 |
|
---|
70 |
theTicks = get(gca, [theTickAxis(k) 'Tick']); |
---|
71 |
theTickLabels = cell(size(theTicks)); |
---|
72 |
for i = 1:length(theTicks) |
---|
73 |
theTicklabels{i} = ''; |
---|
74 |
if rem(i, 2) |
---|
75 |
if nargin < 2 |
---|
76 |
theTickLabels{i} = datestr(theTicks(i)+theBias); |
---|
77 |
else |
---|
78 |
theTickLabels{i} = datestr(theTicks(i)+theBias, theDateFormat); |
---|
79 |
end |
---|
80 |
end |
---|
81 |
end |
---|
82 |
set(gca, [theTickAxis(k) 'Tick'], theTicks, ... |
---|
83 |
[theTickAxis(k) 'TickLabel'], theTickLabels) |
---|
84 |
end |
---|
85 |
|
---|
86 |
% Make resizeable if called directly. |
---|
87 |
|
---|
88 |
if isempty(gcbo) |
---|
89 |
if nargin < 2 |
---|
90 |
theResizeFcn = ['dateaxis(''' theTickAxis ''');']; |
---|
91 |
elseif ischar(theDateFormat) |
---|
92 |
theResizeFcn = ['dateaxis(''' theTickAxis ''', ''' theDateFormat ''', ' num2str(theBias) ');']; |
---|
93 |
else |
---|
94 |
theResizeFcn = ['dateaxis(''' theTickAxis ''', ' int2str(theDateFormat) ', ' num2str(theBias) ');']; |
---|
95 |
end |
---|
96 |
set(get(gca, 'Parent'), 'ResizeFcn', theResizeFcn) |
---|
97 |
end |
---|