<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887</link>
    <title>MATLAB Central Newsreader - Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
    <description>Feed for thread: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 07 Nov 2007 00:39:30 -0500</pubDate>
      <title>Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#400116</link>
      <author>Rob Newman</author>
      <description>Hi there,&lt;br&gt;
&lt;br&gt;
I am plotting some data where the x co-ordinate is in epoch seconds (or unix &lt;br&gt;
time, seconds since 1970-01-01 00:00:00). I would like to convert *just* the &lt;br&gt;
x-axis labels to an equivalent time string. For example, if I have the x-axis &lt;br&gt;
labels (automatically created by Matlab):&lt;br&gt;
&lt;br&gt;
1089865982&lt;br&gt;
1089867030&lt;br&gt;
1089868078&lt;br&gt;
1089869126&lt;br&gt;
1089870174&lt;br&gt;
1089871222&lt;br&gt;
1089872270&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I would like these to display as:&lt;br&gt;
&lt;br&gt;
2004-07-15 04:33:02&lt;br&gt;
2004-07-15 04:50:30&lt;br&gt;
2004-07-15 05:07:58&lt;br&gt;
2004-07-15 05:25:26&lt;br&gt;
2004-07-15 05:42:54&lt;br&gt;
2004-07-15 06:00:22&lt;br&gt;
2004-07-15 06:17:50&lt;br&gt;
&lt;br&gt;
I have read about the graphics object properties like XTickLabel and XTick, &lt;br&gt;
but I cannot see documented anywhere how to format the tick labels.&lt;br&gt;
&lt;br&gt;
Thanks in advance. </description>
    </item>
    <item>
      <pubDate>Wed, 07 Nov 2007 01:07:41 -0500</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#400117</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;fgr1g2$t5g$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Rob Newman &amp;lt;rlnewman@ucsd.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt;I am plotting some data where the x co-ordinate is in epoch seconds (or unix &lt;br&gt;
&amp;gt;time, seconds since 1970-01-01 00:00:00). I would like to convert *just* the &lt;br&gt;
&amp;gt;x-axis labels to an equivalent time string.&lt;br&gt;
&lt;br&gt;
&amp;gt;I would like these to display as:&lt;br&gt;
&lt;br&gt;
&amp;gt;2004-07-15 04:33:02&lt;br&gt;
&lt;br&gt;
After creating the plot, pull out the XTick property of the&lt;br&gt;
axis. Convert those to serial dates and format those serial&lt;br&gt;
dates using format 31 of datestr. Set the axis XTickLabelMode&lt;br&gt;
to 'manual' and set the axis XTickLabel to the formatted dates.&lt;br&gt;
&lt;br&gt;
doc datenum&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;A serial date number represents the whole and fractional number&lt;br&gt;
&amp;nbsp;&amp;nbsp;of days from a specific date and time, where datenum('Jan-1-0000&lt;br&gt;
&amp;nbsp;&amp;nbsp;00:00:00') returns the number 1.&lt;br&gt;
&lt;br&gt;
so convert Jan 1 1970 00:00:00 to a serial date once, and &lt;br&gt;
add to that the epoch seconds divided by 24*60*60 to get the&lt;br&gt;
serial date number to format.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;I was very young in those days, but I was also rather dim.&quot;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Christopher Priest</description>
    </item>
    <item>
      <pubDate>Wed, 07 Nov 2007 16:50:18 -0500</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#400214</link>
      <author>Dan Haeg</author>
      <description>&quot;Rob Newman&quot; &amp;lt;rlnewman@ucsd.edu&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fgr1g2$t5g$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi there,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am plotting some data where the x co-ordinate is in&lt;br&gt;
epoch seconds (or unix &lt;br&gt;
&amp;gt; time, seconds since 1970-01-01 00:00:00). I would like to&lt;br&gt;
convert *just* the &lt;br&gt;
&amp;gt; x-axis labels to an equivalent time string. For example,&lt;br&gt;
if I have the x-axis &lt;br&gt;
&amp;gt; labels (automatically created by Matlab):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1089865982&lt;br&gt;
&amp;gt; 1089867030&lt;br&gt;
&amp;gt; 1089868078&lt;br&gt;
&amp;gt; 1089869126&lt;br&gt;
&amp;gt; 1089870174&lt;br&gt;
&amp;gt; 1089871222&lt;br&gt;
&amp;gt; 1089872270&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I would like these to display as:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2004-07-15 04:33:02&lt;br&gt;
&amp;gt; 2004-07-15 04:50:30&lt;br&gt;
&amp;gt; 2004-07-15 05:07:58&lt;br&gt;
&amp;gt; 2004-07-15 05:25:26&lt;br&gt;
&amp;gt; 2004-07-15 05:42:54&lt;br&gt;
&amp;gt; 2004-07-15 06:00:22&lt;br&gt;
&amp;gt; 2004-07-15 06:17:50&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have read about the graphics object properties like&lt;br&gt;
XTickLabel and XTick, &lt;br&gt;
&amp;gt; but I cannot see documented anywhere how to format the&lt;br&gt;
tick labels.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks in advance. &lt;br&gt;
&lt;br&gt;
See the help for datetick. it may be what you are looking for.&lt;br&gt;
Dan</description>
    </item>
    <item>
      <pubDate>Wed, 07 Nov 2007 19:27:37 -0500</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#400242</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;fgsqca$dbc$1@fred.mathworks.com&amp;gt;, Dan Haeg &amp;lt;haegd@msoe.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt;&quot;Rob Newman&quot; &amp;lt;rlnewman@ucsd.edu&amp;gt; wrote in message&lt;br&gt;
&amp;gt;&amp;lt;fgr1g2$t5g$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; I am plotting some data where the x co-ordinate is in&lt;br&gt;
&amp;gt;epoch seconds (or unix &lt;br&gt;
&amp;gt;&amp;gt; time, seconds since 1970-01-01 00:00:00). I would like to&lt;br&gt;
&amp;gt;convert *just* the &lt;br&gt;
&amp;gt;&amp;gt; x-axis labels to an equivalent time string.&lt;br&gt;
&lt;br&gt;
&amp;gt;See the help for datetick. it may be what you are looking for.&lt;br&gt;
&lt;br&gt;
datetick requires that the data for the axis must be in&lt;br&gt;
serial date format, which &quot;seconds since 1970-01-01 00:00:00&quot;&lt;br&gt;
is not.&lt;br&gt;
&lt;br&gt;
However, since the labels are going to be replaced anyhow,&lt;br&gt;
Rob could convert the x to serial date format and use that as&lt;br&gt;
the x coordinate, and use datetick('x',31). It might make a difference&lt;br&gt;
as to exactly which x are chosen for the tick placement&lt;br&gt;
(matlab likes to place ticks at &quot;nice numbers&quot;), but the result&lt;br&gt;
might be acceptable. It would be slightly easier to implement&lt;br&gt;
than my earlier suggestion.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;No one has the right to destroy another person's belief by&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;demanding empirical evidence.&quot;                -- Ann Landers</description>
    </item>
    <item>
      <pubDate>Wed, 07 Nov 2007 22:30:37 -0500</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#400262</link>
      <author>Rob Newman</author>
      <description>Thanks everyone for your help - I am trying to implement this now.&lt;br&gt;
&lt;br&gt;
Best regards.</description>
    </item>
    <item>
      <pubDate>Tue, 11 Mar 2008 12:02:02 -0400</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#420174</link>
      <author>Dirco du Toit</author>
      <description>&amp;gt; datetick requires that the data for the axis must&lt;br&gt;
&amp;gt; be in serial date format, which &quot;seconds since&lt;br&gt;
&amp;gt; 1970-01-01 00:00:00&quot; is not.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
The way I did it was to add the datenum for 1970-01-01 to &lt;br&gt;
my time value, then convert that to a datestr (otherwise it &lt;br&gt;
still looks like a number and not a date).&lt;br&gt;
&lt;br&gt;
MyDateNum = (datenum([1970 1 1 0 0 0])*86400 + &lt;br&gt;
MyTimeValue) / 86400;&lt;br&gt;
MyDateStr = datestr(MyDateNum, 'yyyy/mm/dd HH:MM:SS');&lt;br&gt;
&lt;br&gt;
Just remember that your custom X-tick labels are now text &lt;br&gt;
values, so it won't scale along with your plot if you &lt;br&gt;
resize it. (I had to make my own GUI to make it recalculate &lt;br&gt;
the dates after every window resize.)</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 15:18:02 -0500</pubDate>
      <title>Re: Convert x-axis plot labels from epoch seconds to YYYY-MM-DD HH:mm:ss string?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158887#692072</link>
      <author>Ken </author>
      <description>Any ideas on how to make that gui? Would it require making controls to do the zooming or can you do it using the standard charting toolbar?&lt;br&gt;
&lt;br&gt;
THanks.&lt;br&gt;
&lt;br&gt;
&quot;Dirco du Toit&quot; &amp;lt;fake@dummy.com&amp;gt; wrote in message &amp;lt;fr5sbq$rcn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; datetick requires that the data for the axis must&lt;br&gt;
&amp;gt; &amp;gt; be in serial date format, which &quot;seconds since&lt;br&gt;
&amp;gt; &amp;gt; 1970-01-01 00:00:00&quot; is not.&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt; The way I did it was to add the datenum for 1970-01-01 to &lt;br&gt;
&amp;gt; my time value, then convert that to a datestr (otherwise it &lt;br&gt;
&amp;gt; still looks like a number and not a date).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; MyDateNum = (datenum([1970 1 1 0 0 0])*86400 + &lt;br&gt;
&amp;gt; MyTimeValue) / 86400;&lt;br&gt;
&amp;gt; MyDateStr = datestr(MyDateNum, 'yyyy/mm/dd HH:MM:SS');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Just remember that your custom X-tick labels are now text &lt;br&gt;
&amp;gt; values, so it won't scale along with your plot if you &lt;br&gt;
&amp;gt; resize it. (I had to make my own GUI to make it recalculate &lt;br&gt;
&amp;gt; the dates after every window resize.)</description>
    </item>
  </channel>
</rss>

