<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/171723</link>
    <title>MATLAB Central Newsreader - reading date_time in PM/AM format from an ascii file</title>
    <description>Feed for thread: reading date_time in PM/AM format from an ascii file</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>Sun, 29 Jun 2008 04:41:01 -0400</pubDate>
      <title>reading date_time in PM/AM format from an ascii file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/171723#440096</link>
      <author>Maria Prokopenko</author>
      <description>Hello,&lt;br&gt;
i am trying to read into Matlab ascii files  (part of the&lt;br&gt;
first line is given here as an example, then the same string&lt;br&gt;
repeats 7 more times, 8 total, in a each row of each file)&lt;br&gt;
&lt;br&gt;
4/7/2008 3:02:42 AM	0.245	2.924686e-009 &lt;br&gt;
&lt;br&gt;
I need to convert the dates into numerical form, so i can&lt;br&gt;
time-average the data etc.&lt;br&gt;
&lt;br&gt;
I am trying to use textscan to read the am/pm format of the&lt;br&gt;
dates, and while this does read 'AM' or 'PM' as a string i&lt;br&gt;
cannot convert the whole string back into a date_time&lt;br&gt;
format. that's what i am doing:&lt;br&gt;
&lt;br&gt;
eims = [];&lt;br&gt;
&amp;nbsp;E = dir('EIMS_ascii_formatted');&lt;br&gt;
&amp;nbsp;cd EIMS_ascii_formatted\&lt;br&gt;
for i =3:length(E)    &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_file_name = E(i).name;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(eims_file_name)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fid = fopen(eims_file_name);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eimst =  textscan(fid,['%d/%d/%d %d:%d:%d %s %f32 %f32&lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32&lt;br&gt;
%d/%d/%d %d:%d:%d %s %f32 %f32'],[72 inf]');&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,1)=eimst{1};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,2)=eimst{2};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,3)=eimst{3};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,4)=eimst{4};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,5)=eimst{5};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,6)=eimst{6};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;eims_dates(:,7)=eimst{7}; (% here the problem comes: AM&lt;br&gt;
or PM is not read%)&lt;br&gt;
&lt;br&gt;
% i also tried%&lt;br&gt;
&lt;br&gt;
eims_dates=eimst(:,1:7); % this did not work either%&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;fclose(fid);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;eims_dates = datenum(eims(:,1:7))&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
My code does not work. Any help will be very much appreciated,&lt;br&gt;
&lt;br&gt;
Masha</description>
    </item>
    <item>
      <pubDate>Sun, 29 Jun 2008 14:12:01 -0400</pubDate>
      <title>reading date_time in PM/AM format from an ascii file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/171723#440123</link>
      <author>Georgios </author>
      <description>&quot;Maria Prokopenko&quot; &amp;lt;masha.prokopenko@gmail.com&amp;gt; wrote in&lt;br&gt;
message &amp;lt;g473ot$er2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; i am trying to read into Matlab ascii files  (part of the&lt;br&gt;
&amp;gt; first line is given here as an example, then the same string&lt;br&gt;
&amp;gt; repeats 7 more times, 8 total, in a each row of each file)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 4/7/2008 3:02:42 AM	0.245	2.924686e-009 &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need to convert the dates into numerical form, so i can&lt;br&gt;
&amp;gt; time-average the data etc.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am trying to use textscan to read the am/pm format of the&lt;br&gt;
&amp;gt; dates, and while this does read 'AM' or 'PM' as a string i&lt;br&gt;
&amp;gt; cannot convert the whole string back into a date_time&lt;br&gt;
&amp;gt; format. that's what i am doing:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; eims = [];&lt;br&gt;
&amp;gt;  E = dir('EIMS_ascii_formatted');&lt;br&gt;
&amp;gt;  cd EIMS_ascii_formatted\&lt;br&gt;
&amp;gt; for i =3:length(E)    &lt;br&gt;
&amp;gt;     eims_file_name = E(i).name;&lt;br&gt;
&amp;gt;     disp(eims_file_name)&lt;br&gt;
&amp;gt;     fid = fopen(eims_file_name);&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     eimst =  textscan(fid,['%d/%d/%d %d:%d:%d %s %f32 %f32&lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32 &lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32&lt;br&gt;
&amp;gt; %d/%d/%d %d:%d:%d %s %f32 %f32'],[72 inf]');&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt;    eims_dates(:,1)=eimst{1};&lt;br&gt;
&amp;gt;    eims_dates(:,2)=eimst{2};&lt;br&gt;
&amp;gt;    eims_dates(:,3)=eimst{3};&lt;br&gt;
&amp;gt;    eims_dates(:,4)=eimst{4};&lt;br&gt;
&amp;gt;    eims_dates(:,5)=eimst{5};&lt;br&gt;
&amp;gt;    eims_dates(:,6)=eimst{6};&lt;br&gt;
&amp;gt;    eims_dates(:,7)=eimst{7}; (% here the problem comes: AM&lt;br&gt;
&amp;gt; or PM is not read%)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % i also tried%&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; eims_dates=eimst(:,1:7); % this did not work either%&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;    fclose(fid);&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;   eims_dates = datenum(eims(:,1:7))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My code does not work. Any help will be very much appreciated,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Masha&lt;br&gt;
&lt;br&gt;
The datestr command might be helpful.  I have not tried it&lt;br&gt;
with your code example, because I am not at work, where I&lt;br&gt;
run Matlab.  There are examples of use at the Mathworks help&lt;br&gt;
desk.&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;help datestr &lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/datestr.html&amp;http://www.mathworks.com/cgi-bin/texis/webinator/search/?db=MSS&amp;prox=page&amp;rorder=750&amp;rprox=750&amp;rdfreq=500&amp;rwfreq=500&amp;rlead=250&amp;sufs=0&amp;order=r&amp;is_summary_on=1&amp;ResultCount=10&amp;query=datestr&amp;submitButtonName=Search&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/datestr.html&amp;http://www.mathworks.com/cgi-bin/texis/webinator/search/?db=MSS&amp;prox=page&amp;rorder=750&amp;rprox=750&amp;rdfreq=500&amp;rwfreq=500&amp;rlead=250&amp;sufs=0&amp;order=r&amp;is_summary_on=1&amp;ResultCount=10&amp;query=datestr&amp;submitButtonName=Search&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Regards,&lt;br&gt;
Georgios</description>
    </item>
    <item>
      <pubDate>Mon, 30 Jun 2008 10:54:01 -0400</pubDate>
      <title>reading date_time in PM/AM format from an ascii file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/171723#440236</link>
      <author>Andres </author>
      <description>&quot;Maria Prokopenko&quot; &amp;lt;masha.prokopenko@gmail.com&amp;gt; wrote in &lt;br&gt;
message &amp;lt;g473ot$er2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; i am trying to read into Matlab ascii files  (part of the&lt;br&gt;
&amp;gt; first line is given here as an example, then the same &lt;br&gt;
string&lt;br&gt;
&amp;gt; repeats 7 more times, 8 total, in a each row of each file)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 4/7/2008 3:02:42 AM	0.245	2.924686e-009 &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need to convert the dates into numerical form, so i can&lt;br&gt;
&amp;gt; time-average the data etc.&lt;br&gt;
&amp;gt; [..]&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Maria,&lt;br&gt;
&lt;br&gt;
there's an easy solution - among others - with txt2mat from &lt;br&gt;
the file exchange:&lt;br&gt;
&lt;br&gt;
filename = 'c:\myFile.txt';&lt;br&gt;
&lt;br&gt;
A = txt2mat(filename,'ReplaceExpr', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{{'AM','00'}, {'PM','12'}});&lt;br&gt;
&lt;br&gt;
%{&lt;br&gt;
A contains separate columns for day, month, year...&lt;br&gt;
%}&lt;br&gt;
&lt;br&gt;
dateVector = [A(:,3), A(:,2), A(:,1), A(:,4)+ A(:,7), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;A(:,5), A(:,6)];&lt;br&gt;
&lt;br&gt;
%{  &lt;br&gt;
This is the 'Date Vector' format you can find in the help &lt;br&gt;
of datenum and other date related functions. A(:,7) &lt;br&gt;
contains the additional hour number from &quot;AM&quot; or &quot;PM&quot; (0 or &lt;br&gt;
12, resp.), that ist added to A(:,4). Note that I assumed &lt;br&gt;
the month number to be at the second position in your file, &lt;br&gt;
otherwise swap A(:,2) and A(:,1) in the dateVector &lt;br&gt;
definition. &lt;br&gt;
%}&lt;br&gt;
&lt;br&gt;
% Now you can use matlab's date functions, e.g.&lt;br&gt;
n = datenum(dateVector);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I checked this on a file containing the following lines:&lt;br&gt;
4/7/2008 3:02:42 AM 0.245 2.924686e-009 &lt;br&gt;
4/7/2008 3:02:42 PM 0.245 2.924686e-009 &lt;br&gt;
5/7/2008 3:02:42 PM 0.245 2.924686e-009 &lt;br&gt;
6/7/2008 3:02:42 AM 0.245 2.924686e-009&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hth, regards&lt;br&gt;
Andres</description>
    </item>
    <item>
      <pubDate>Mon, 30 Jun 2008 13:28:01 -0400</pubDate>
      <title>reading date_time in PM/AM format from an ascii file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/171723#440267</link>
      <author>Maria Prokopenko</author>
      <description>&quot;Andres &quot; &amp;lt;rantore@werb.de&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g4ae09$s37$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Maria Prokopenko&quot; &amp;lt;masha.prokopenko@gmail.com&amp;gt; wrote in &lt;br&gt;
&amp;gt; message &amp;lt;g473ot$er2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; i am trying to read into Matlab ascii files  (part of the&lt;br&gt;
&amp;gt; &amp;gt; first line is given here as an example, then the same &lt;br&gt;
&amp;gt; string&lt;br&gt;
&amp;gt; &amp;gt; repeats 7 more times, 8 total, in a each row of each file)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 4/7/2008 3:02:42 AM	0.245	2.924686e-009 &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I need to convert the dates into numerical form, so i can&lt;br&gt;
&amp;gt; &amp;gt; time-average the data etc.&lt;br&gt;
&amp;gt; &amp;gt; [..]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thank you very much for your help! i am trying it out right now.&lt;br&gt;
&lt;br&gt;
masha&lt;br&gt;
&amp;gt; Hi Maria,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; there's an easy solution - among others - with txt2mat from &lt;br&gt;
&amp;gt; the file exchange:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; filename = 'c:\myFile.txt';&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A = txt2mat(filename,'ReplaceExpr', ...&lt;br&gt;
&amp;gt;     {{'AM','00'}, {'PM','12'}});&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %{&lt;br&gt;
&amp;gt; A contains separate columns for day, month, year...&lt;br&gt;
&amp;gt; %}&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; dateVector = [A(:,3), A(:,2), A(:,1), A(:,4)+ A(:,7), ...&lt;br&gt;
&amp;gt;               A(:,5), A(:,6)];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %{  &lt;br&gt;
&amp;gt; This is the 'Date Vector' format you can find in the help &lt;br&gt;
&amp;gt; of datenum and other date related functions. A(:,7) &lt;br&gt;
&amp;gt; contains the additional hour number from &quot;AM&quot; or &quot;PM&quot; (0 or &lt;br&gt;
&amp;gt; 12, resp.), that ist added to A(:,4). Note that I assumed &lt;br&gt;
&amp;gt; the month number to be at the second position in your file, &lt;br&gt;
&amp;gt; otherwise swap A(:,2) and A(:,1) in the dateVector &lt;br&gt;
&amp;gt; definition. &lt;br&gt;
&amp;gt; %}&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Now you can use matlab's date functions, e.g.&lt;br&gt;
&amp;gt; n = datenum(dateVector);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I checked this on a file containing the following lines:&lt;br&gt;
&amp;gt; 4/7/2008 3:02:42 AM 0.245 2.924686e-009 &lt;br&gt;
&amp;gt; 4/7/2008 3:02:42 PM 0.245 2.924686e-009 &lt;br&gt;
&amp;gt; 5/7/2008 3:02:42 PM 0.245 2.924686e-009 &lt;br&gt;
&amp;gt; 6/7/2008 3:02:42 AM 0.245 2.924686e-009&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hth, regards&lt;br&gt;
&amp;gt; Andres</description>
    </item>
  </channel>
</rss>

