Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?
Date: Tue, 11 Mar 2008 12:02:02 +0000 (UTC)
Organization: RRS
Lines: 16
Message-ID: <fr5sbq$rcn$1@fred.mathworks.com>
References: <fgr1g2$t5g$1@fred.mathworks.com> <fgsqca$dbc$1@fred.mathworks.com> <fgt3j9$k07$1@canopus.cc.umanitoba.ca>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205236922 28055 172.30.248.35 (11 Mar 2008 12:02:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 11 Mar 2008 12:02:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1311477
Xref: news.mathworks.com comp.soft-sys.matlab:456511



> 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.
 
The way I did it was to add the datenum for 1970-01-01 to 
my time value, then convert that to a datestr (otherwise it 
still looks like a number and not a date).

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.)