Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?
Date: Wed, 7 Nov 2007 01:07:41 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 27
Message-ID: <fgr34t$3od$1@canopus.cc.umanitoba.ca>
References: <fgr1g2$t5g$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1194397661 3853 192.70.172.160 (7 Nov 2007 01:07:41 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Wed, 7 Nov 2007 01:07:41 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:436344



In article <fgr1g2$t5g$1@fred.mathworks.com>,
Rob Newman <rlnewman@ucsd.edu> wrote:
>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.

>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