<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474</link>
    <title>MATLAB Central Newsreader - How to import timestamp (5:48:05 ) to a format ML can handle</title>
    <description>Feed for thread: How to import timestamp (5:48:05 ) to a format ML can handle</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>Tue, 06 Oct 2009 19:56:50 -0400</pubDate>
      <title>How to import timestamp (5:48:05 ) to a format ML can handle</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474#685160</link>
      <author>AMK</author>
      <description>Hi,&lt;br&gt;
I have a datafile that I'm reading into ML and am stuck on how to get the timestamp into ML in a form that it will be able to handle.  Here is my current import script.  Any suggestions?  The whole file is tab delimited but the timestamp cell has :, which I hope may be of some help here.&lt;br&gt;
&lt;br&gt;
[code]&lt;br&gt;
fnames = dir('*.ddf');&lt;br&gt;
dr1 = 10; dc1 = 1; dr2 = 10; dc2 = 1; %This defines where the time is located within the .ddf file&lt;br&gt;
dtcols = (dr2-dr1)+1; %Defines length of the data column&lt;br&gt;
dtrows = length(fnames);  %Defines the length of the data rows&lt;br&gt;
ch1_dt = zeros(dtrows, dtcols);    %Initializes a matrix to store the data&lt;br&gt;
for n = 1:length(fnames)    %Start the for loop for the file names&lt;br&gt;
&amp;nbsp;&amp;nbsp;ch1_dt(n,:) = dlmread(fnames(n).name, '\t', [dr1 dc1 dr2 dc2])'; %Read in the data&lt;br&gt;
&amp;nbsp;&amp;nbsp;end %End the loop&lt;br&gt;
[/code]&lt;br&gt;
&lt;br&gt;
Here is a sample of the '\t' delimited datafile:&lt;br&gt;
date	9/30/2009&lt;br&gt;
time	5:48:05&lt;br&gt;
&lt;br&gt;
Obviously, my next question will be how to import the date too, but that's less critical.&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Tue, 06 Oct 2009 20:30:19 -0400</pubDate>
      <title>Re: How to import timestamp (5:48:05 ) to a format ML can handle</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474#685167</link>
      <author>TideMan</author>
      <description>On Oct 7, 8:56&#160;am, AMK &amp;lt;kennas...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have a datafile that I'm reading into ML and am stuck on how to get the timestamp into ML in a form that it will be able to handle. &#160;Here is my current import script. &#160;Any suggestions? &#160;The whole file is tab delimited but the timestamp cell has :, which I hope may be of some help here.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; [code]&lt;br&gt;
&amp;gt; fnames = dir('*.ddf');&lt;br&gt;
&amp;gt; dr1 = 10; dc1 = 1; dr2 = 10; dc2 = 1; %This defines where the time is located within the .ddf file&lt;br&gt;
&amp;gt; dtcols = (dr2-dr1)+1; %Defines length of the data column&lt;br&gt;
&amp;gt; dtrows = length(fnames); &#160;%Defines the length of the data rows&lt;br&gt;
&amp;gt; ch1_dt = zeros(dtrows, dtcols); &#160; &#160;%Initializes a matrix to store the data&lt;br&gt;
&amp;gt; for n = 1:length(fnames) &#160; &#160;%Start the for loop for the file names&lt;br&gt;
&amp;gt; &#160; ch1_dt(n,:) = dlmread(fnames(n).name, '\t', [dr1 dc1 dr2 dc2])'; %Read in the data&lt;br&gt;
&amp;gt; &#160; end %End the loop&lt;br&gt;
&amp;gt; [/code]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Here is a sample of the '\t' delimited datafile:&lt;br&gt;
&amp;gt; date &#160; &#160;9/30/2009&lt;br&gt;
&amp;gt; time &#160; &#160;5:48:05&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Obviously, my next question will be how to import the date too, but that's less critical.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
Matlab can handle a wide variety of date and time formats, but you&lt;br&gt;
need to import them as strings (like '9/30/2009' and '5:48:05'):&lt;br&gt;
help datenum&lt;br&gt;
Try this:&lt;br&gt;
datestr(datenum('9/30/2009 5:48:05','mm/dd/yyyy HH:MM:SS'))</description>
    </item>
    <item>
      <pubDate>Tue, 06 Oct 2009 22:12:19 -0400</pubDate>
      <title>Re: How to import timestamp (5:48:05 ) to a format ML can handle</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474#685190</link>
      <author>AMK</author>
      <description>Great, however, my time and date values are nestled quite comfortably amongst the raw data file that has strings, numbers, is mostly tab delimited but also has potential delimiters in certain cells (such as the date and time).  I'm not sure where to call the datenum().  My time location actually gets defined in line 2 of the code, but gets inserted from within the for loop.  &lt;br&gt;
&lt;br&gt;
Sincerely,&lt;br&gt;
Still stumped</description>
    </item>
    <item>
      <pubDate>Tue, 06 Oct 2009 22:39:12 -0400</pubDate>
      <title>Re: How to import timestamp (5:48:05 ) to a format ML can handle</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474#685196</link>
      <author>AMK</author>
      <description>This:&lt;br&gt;
&lt;br&gt;
[code]&lt;br&gt;
for n = 1:length(fnames)    %Start the for loop for the file names&lt;br&gt;
&amp;nbsp;&amp;nbsp;ch4_dt(n,:) = dlmread(fnames(n).name, '\t', datenum([dr1 dc1 dr2 dc2]))'; %Read in the data&lt;br&gt;
&amp;nbsp;&amp;nbsp;%timestamp(n,:) = dlmread(fnames(n).name, ';', [tr1 tc1 tr2 tc2])';    %Read in the timestamps&lt;br&gt;
end %End the loop&lt;br&gt;
[/code]&lt;br&gt;
&lt;br&gt;
only gets me a 5, which is the first value in the timestamp shown in the original problem.</description>
    </item>
    <item>
      <pubDate>Wed, 07 Oct 2009 17:43:06 -0400</pubDate>
      <title>Re: How to import timestamp (5:48:05 ) to a format ML can handle</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262474#685392</link>
      <author>Leslie McBrayer</author>
      <description>&lt;br&gt;
&quot;AMK&quot; &amp;lt;kennaster@gmail.com&amp;gt; wrote in message &lt;br&gt;
news:655747749.23145.1254868782259.JavaMail.root@gallium.mathforum.org...&lt;br&gt;
&amp;gt; This:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; [code]&lt;br&gt;
&amp;gt; for n = 1:length(fnames)    %Start the for loop for the file names&lt;br&gt;
&amp;gt;  ch4_dt(n,:) = dlmread(fnames(n).name, '\t', datenum([dr1 dc1 dr2 dc2]))'; &lt;br&gt;
&amp;gt; %Read in the data&lt;br&gt;
&amp;gt;  %timestamp(n,:) = dlmread(fnames(n).name, ';', [tr1 tc1 tr2 tc2])'; &lt;br&gt;
&amp;gt; %Read in the timestamps&lt;br&gt;
&amp;gt; end %End the loop&lt;br&gt;
&amp;gt; [/code]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; only gets me a 5, which is the first value in the timestamp shown in the &lt;br&gt;
&amp;gt; original problem.&lt;br&gt;
&lt;br&gt;
The dlmread function cannot read formatted dates and times.  Consider using &lt;br&gt;
textscan to read the dates/times in as strings (type &quot;doc textscan&quot; at the &lt;br&gt;
command prompt for more info).  Then you can convert the strings to numbers &lt;br&gt;
using datenum. </description>
    </item>
  </channel>
</rss>

