I am plotting some data where the x co-ordinate is in epoch seconds (or unix
time, seconds since 1970-01-01 00:00:00). I would like to convert *just* the
x-axis labels to an equivalent time string. For example, if I have the x-axis
labels (automatically created by Matlab):
1089865982
1089867030
1089868078
1089869126
1089870174
1089871222
1089872270
I would like these to display as:
2004-07-15 04:33:02
2004-07-15 04:50:30
2004-07-15 05:07:58
2004-07-15 05:25:26
2004-07-15 05:42:54
2004-07-15 06:00:22
2004-07-15 06:17:50
I have read about the graphics object properties like XTickLabel and XTick,
but I cannot see documented anywhere how to format the tick labels.
Thanks in advance.
>I would like these to display as:
>2004-07-15 04:33:02
After creating the plot, pull out the XTick property of the
axis. Convert those to serial dates and format those serial
dates using format 31 of datestr. Set the axis XTickLabelMode
to 'manual' and set the axis XTickLabel to the formatted dates.
doc datenum
A serial date number represents the whole and fractional number
of days from a specific date and time, where datenum('Jan-1-0000
00:00:00') returns the number 1.
so convert Jan 1 1970 00:00:00 to a serial date once, and
add to that the epoch seconds divided by 24*60*60 to get the
serial date number to format.
--
"I was very young in those days, but I was also rather dim."
-- Christopher Priest
See the help for datetick. it may be what you are looking for.
Dan
>See the help for datetick. it may be what you are looking for.
datetick requires that the data for the axis must be in
serial date format, which "seconds since 1970-01-01 00:00:00"
is not.
However, since the labels are going to be replaced anyhow,
Rob could convert the x to serial date format and use that as
the x coordinate, and use datetick('x',31). It might make a difference
as to exactly which x are chosen for the tick placement
(matlab likes to place ticks at "nice numbers"), but the result
might be acceptable. It would be slightly easier to implement
than my earlier suggestion.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Best regards.
MyDateNum = (datenum([1970 1 1 0 0 0])*86400 +
MyTimeValue) / 86400;
MyDateStr = datestr(MyDateNum, 'yyyy/mm/dd HH:MM:SS');
Just remember that your custom X-tick labels are now text
values, so it won't scale along with your plot if you
resize it. (I had to make my own GUI to make it recalculate
the dates after every window resize.)
THanks.
"Dirco du Toit" <fa...@dummy.com> wrote in message <fr5sbq$rcn$1...@fred.mathworks.com>...