<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Atomic clock + alarm challenge</title>
	<atom:link href="http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/</link>
	<description>&#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093599&#38;objectType=author&#34;&#62;Brett&#60;/a&#62; &#38; &#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094142&#38;objectType=author&#34;&#62;Jiro&#60;/a&#62; share favorite user-contributed submissions from the File Exchange.</description>
	<lastBuildDate>Thu, 16 Feb 2012 21:37:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12181</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Tue, 22 Jul 2008 06:54:49 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12181</guid>
		<description>And here it is:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=20693&amp;objectType=file</description>
		<content:encoded><![CDATA[<p>And here it is:<br />
<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=20693&#038;objectType=file" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=20693&#038;objectType=file</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12087</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Mon, 14 Jul 2008 12:55:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12087</guid>
		<description>Well, when in doubt, guess. Assuming your system clock isn&#039;t off by more than 1 hour and you aren&#039;t in one of these half-hour time-zones, this will work.

I get the current time with the following:
&lt;pre&gt;
% Get the current time in hours (12hour format).
crnt = mod(now+getCurrentTimeDelta,0.5)*24;

function [ timeDelta ] = getCurrentTimeDelta( timeZone )
%GETCURRENTTIMEDELTA Gets the offset in time of the system clock.
%Time format is compatible with now. To get exact time, add the
%return value to the current system time. As an optional argument,
%supply the time-zone.


URL = &#039;http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;;
atomTime = datenum(regexp(urlread(URL), ...
   &#039;(.*)\sUTC&#039;,&#039;tokens&#039;,&#039;once&#039;),&#039;mmm. dd, HH:MM:SS&#039;);
sysTime = now;

if ( nargin == 0 ) 
    timeZone = 2; %The timezone in hours.
    timeDelta = atomTime - sysTime + timeZone/24;
else
    % Assume time diff is less than 1 hour
    timeDelta = atomTime - sysTime;
    timeDeltaInHours = timeDelta*24;    
    timeDelta = (timeDeltaInHours - round(timeDeltaInHours))/24;    
    fprintf ( &#039;Time delta: %gs.\n&#039;, timeDelta*24*60*60 );
end

end
%EOF
&lt;/pre&gt;

I also submitted the complete updated function to the file exchange, but it seems it will take a few days for it to be processed, so you will have to be patient. It has been sumbitted under the title &quot;Atomic reminder&quot;.</description>
		<content:encoded><![CDATA[<p>Well, when in doubt, guess. Assuming your system clock isn&#8217;t off by more than 1 hour and you aren&#8217;t in one of these half-hour time-zones, this will work.</p>
<p>I get the current time with the following:</p>
<pre>
% Get the current time in hours (12hour format).
crnt = mod(now+getCurrentTimeDelta,0.5)*24;

function [ timeDelta ] = getCurrentTimeDelta( timeZone )
%GETCURRENTTIMEDELTA Gets the offset in time of the system clock.
%Time format is compatible with now. To get exact time, add the
%return value to the current system time. As an optional argument,
%supply the time-zone.

URL = '<a href="http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;" rel="nofollow">http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;</a>;
atomTime = datenum(regexp(urlread(URL), ...
   '(.*)\sUTC','tokens','once'),'mmm. dd, HH:MM:SS');
sysTime = now;

if ( nargin == 0 )
    timeZone = 2; %The timezone in hours.
    timeDelta = atomTime - sysTime + timeZone/24;
else
    % Assume time diff is less than 1 hour
    timeDelta = atomTime - sysTime;
    timeDeltaInHours = timeDelta*24;
    timeDelta = (timeDeltaInHours - round(timeDeltaInHours))/24;
    fprintf ( 'Time delta: %gs.\n', timeDelta*24*60*60 );
end

end
%EOF
</pre>
<p>I also submitted the complete updated function to the file exchange, but it seems it will take a few days for it to be processed, so you will have to be patient. It has been sumbitted under the title &#8220;Atomic reminder&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12084</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Mon, 14 Jul 2008 12:09:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12084</guid>
		<description>Daniel, wonderful observation! Unfortunately, MATLAB relies on local system time. Different operating systems feature different interfaces for accessing system time. For example, on Windows you can use the legacy TIME (and DATE) functions.

&lt;pre&gt;
&gt;&gt; !time
The current time is:  8:09:17.33 
Enter the new time: 
&lt;/pre&gt;

Let&#039;s see what other clever users suggest. :)</description>
		<content:encoded><![CDATA[<p>Daniel, wonderful observation! Unfortunately, MATLAB relies on local system time. Different operating systems feature different interfaces for accessing system time. For example, on Windows you can use the legacy TIME (and DATE) functions.</p>
<pre>
>> !time
The current time is:  8:09:17.33
Enter the new time:
</pre>
<p>Let&#8217;s see what other clever users suggest. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12083</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Mon, 14 Jul 2008 11:56:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-12083</guid>
		<description>OK, so I started to implement this and ran into my first cotcha. The URL in question presents time in UTC (and other time zones), but matlab only seems to give time in local time. Is there a way to ask Matlab what timezone it believes it to be in?</description>
		<content:encoded><![CDATA[<p>OK, so I started to implement this and ran into my first cotcha. The URL in question presents time in UTC (and other time zones), but matlab only seems to give time in local time. Is there a way to ask Matlab what timezone it believes it to be in?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11987</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Wed, 02 Jul 2008 12:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11987</guid>
		<description>Okay, so the first part of the challenge has a solution. JesseL&#039;s excellent use of a regular expression made short work of that. But now ... how to use that time stamp in your MATLAB alarm clock to compensate for inaccuracies in your system time? And perhaps more importantly, what is a reasonable tolerance for accuracy in this application?

Cheers
Bob</description>
		<content:encoded><![CDATA[<p>Okay, so the first part of the challenge has a solution. JesseL&#8217;s excellent use of a regular expression made short work of that. But now &#8230; how to use that time stamp in your MATLAB alarm clock to compensate for inaccuracies in your system time? And perhaps more importantly, what is a reasonable tolerance for accuracy in this application?</p>
<p>Cheers<br />
Bob</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11986</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Wed, 02 Jul 2008 12:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11986</guid>
		<description>JesseL, that worked great. 
&lt;pre&gt;
&gt;&gt; URL = &#039;http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;;
&gt;&gt; time = datenum(regexp(urlread(URL),...
     &#039;&lt;BR&gt;(.*)\sUTC&#039;,&#039;tokens&#039;,&#039;once&#039;),&#039;mmm. dd, HH:MM:SS&#039;)
time =
  7.3359e+005
&gt;&gt; datestr(time)
ans =
02-Jul-2008 12:08:18
&lt;/pre&gt;

Jiro, good formatting tips. Here&#039;s a reminder that for anyone who wants to post code snippets be sure to use the &lt;pre&gt; tag around your code like this.
&lt;pre&gt;
&lt;pre&gt;
%your code...
&lt;/pre&gt;
&lt;/pre&gt;

Then if your code includes some kind of &lt;TAG&gt; just replace it with &lt;TAG&gt; when you paste it as a blog comment so it will display correctly, and of course use Preview to make sure. (I had to do that several times.:)</description>
		<content:encoded><![CDATA[<p>JesseL, that worked great. </p>
<pre>
&gt;&gt; URL = '<a href="http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;" rel="nofollow">http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;</a>;
&gt;&gt; time = datenum(regexp(urlread(URL),...
     '&lt;BR&gt;(.*)\sUTC','tokens','once'),'mmm. dd, HH:MM:SS')
time =
  7.3359e+005
&gt;&gt; datestr(time)
ans =
02-Jul-2008 12:08:18
</pre>
<p>Jiro, good formatting tips. Here&#8217;s a reminder that for anyone who wants to post code snippets be sure to use the &lt;pre&gt; tag around your code like this.</p>
<pre>
&lt;pre&gt;
%your code...
&lt;/pre&gt;
</pre>
<p>Then if your code includes some kind of &lt;TAG&gt; just replace it with &amp;lt;TAG&amp;gt; when you paste it as a blog comment so it will display correctly, and of course use Preview to make sure. (I had to do that several times.:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jiro</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11983</link>
		<dc:creator>jiro</dc:creator>
		<pubDate>Wed, 02 Jul 2008 02:18:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11983</guid>
		<description>Yup, I think you&#039;re right, JesseL. I had to use the character entities to display &lt; and &gt; correctly:
&lt;pre&gt;
&lt; and &gt;
&lt;/pre&gt;

The following should be the correct code that you want:

&lt;pre&gt;
URL = &#039;http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;;
time = datenum(regexp(urlread(URL), ...
   &#039;&lt;BR&gt;(.*)\sUTC&#039;,&#039;tokens&#039;,&#039;once&#039;),&#039;mmm. dd, HH:MM:SS&#039;)
&lt;/pre&gt;

P.S. BTW, there&#039;s a &quot;Preview&quot; button just above the comment box, which you can use to preview your comment. This way, you can check to make sure the rendering is correct.</description>
		<content:encoded><![CDATA[<p>Yup, I think you&#8217;re right, JesseL. I had to use the character entities to display < and > correctly:</p>
<pre>
&amp;lt; and &amp;gt;
</pre>
<p>The following should be the correct code that you want:</p>
<pre>
URL = '<a href="http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;" rel="nofollow">http://tycho.usno.navy.mil/cgi-bin/timer.pl&#039;</a>;
time = datenum(regexp(urlread(URL), ...
   '&lt;BR&gt;(.*)\sUTC','tokens','once'),'mmm. dd, HH:MM:SS')
</pre>
<p>P.S. BTW, there&#8217;s a &#8220;Preview&#8221; button just above the comment box, which you can use to preview your comment. This way, you can check to make sure the rendering is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JesseL</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11979</link>
		<dc:creator>JesseL</dc:creator>
		<pubDate>Tue, 01 Jul 2008 21:39:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11979</guid>
		<description>Yup, like I thought, its rendering them.  Because, the lessthan and greaterthan signs are gone from my previous comment.

Replace [ with lessthansign
Replace ] with greaterthansign

Maybe there&#039;s an escape character?
Test: \</description>
		<content:encoded><![CDATA[<p>Yup, like I thought, its rendering them.  Because, the lessthan and greaterthan signs are gone from my previous comment.</p>
<p>Replace [ with lessthansign<br />
Replace ] with greaterthansign</p>
<p>Maybe there&#8217;s an escape character?<br />
Test: \</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JesseL</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11978</link>
		<dc:creator>JesseL</dc:creator>
		<pubDate>Tue, 01 Jul 2008 21:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11978</guid>
		<description>That&#039;s because it didn&#039;t paste the right thing!  I think the webpage is rendering the tag in the regular expression.  The regexp string should be:

&#039;[BR](.*)\sUTC&#039;
You should replace the [ ] with </description>
		<content:encoded><![CDATA[<p>That&#8217;s because it didn&#8217;t paste the right thing!  I think the webpage is rendering the tag in the regular expression.  The regexp string should be:</p>
<p>&#8216;[BR](.*)\sUTC&#8217;<br />
You should replace the [ ] with</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11976</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Tue, 01 Jul 2008 17:02:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/06/27/atomic-clock-alarm-challenge/#comment-11976</guid>
		<description>JesseL, thanks. That&#039;s very close but I got an error.

&lt;pre&gt;
??? Error using ==&gt; datenum at 174
DATENUM failed.

Caused by:
    Error using ==&gt; dtstr2dtnummx
    Failed on converting date string to date number.
&lt;/pre&gt;

Let&#039;s see who fixes that...</description>
		<content:encoded><![CDATA[<p>JesseL, thanks. That&#8217;s very close but I got an error.</p>
<pre>
??? Error using ==> datenum at 174
DATENUM failed.

Caused by:
    Error using ==> dtstr2dtnummx
    Failed on converting date string to date number.
</pre>
<p>Let&#8217;s see who fixes that&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

