Path: news.mathworks.com!not-for-mail
From: "Maria Prokopenko" <masha.prokopenko@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: reading date_time in PM/AM format from an ascii file
Date: Mon, 30 Jun 2008 13:28:01 +0000 (UTC)
Organization: USC
Lines: 63
Message-ID: <g4an11$qs3$1@fred.mathworks.com>
References: <g473ot$er2$1@fred.mathworks.com> <g4ae09$s37$1@fred.mathworks.com>
Reply-To: "Maria Prokopenko" <masha.prokopenko@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1214832481 27523 172.30.248.37 (30 Jun 2008 13:28:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 30 Jun 2008 13:28:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1428337
Xref: news.mathworks.com comp.soft-sys.matlab:476621



"Andres " <rantore@werb.de> wrote in message
<g4ae09$s37$1@fred.mathworks.com>...
> "Maria Prokopenko" <masha.prokopenko@gmail.com> wrote in 
> message <g473ot$er2$1@fred.mathworks.com>...
> > Hello,
> > i am trying to read into Matlab ascii files  (part of the
> > first line is given here as an example, then the same 
> string
> > repeats 7 more times, 8 total, in a each row of each file)
> > 
> > 4/7/2008 3:02:42 AM	0.245	2.924686e-009 
> > 
> > I need to convert the dates into numerical form, so i can
> > time-average the data etc.
> > [..]
> 
> 


Thank you very much for your help! i am trying it out right now.

masha
> Hi Maria,
> 
> there's an easy solution - among others - with txt2mat from 
> the file exchange:
> 
> filename = 'c:\myFile.txt';
> 
> A = txt2mat(filename,'ReplaceExpr', ...
>     {{'AM','00'}, {'PM','12'}});
> 
> %{
> A contains separate columns for day, month, year...
> %}
> 
> dateVector = [A(:,3), A(:,2), A(:,1), A(:,4)+ A(:,7), ...
>               A(:,5), A(:,6)];
> 
> %{  
> This is the 'Date Vector' format you can find in the help 
> of datenum and other date related functions. A(:,7) 
> contains the additional hour number from "AM" or "PM" (0 or 
> 12, resp.), that ist added to A(:,4). Note that I assumed 
> the month number to be at the second position in your file, 
> otherwise swap A(:,2) and A(:,1) in the dateVector 
> definition. 
> %}
> 
> % Now you can use matlab's date functions, e.g.
> n = datenum(dateVector);
> 
> 
> I checked this on a file containing the following lines:
> 4/7/2008 3:02:42 AM 0.245 2.924686e-009 
> 4/7/2008 3:02:42 PM 0.245 2.924686e-009 
> 5/7/2008 3:02:42 PM 0.245 2.924686e-009 
> 6/7/2008 3:02:42 AM 0.245 2.924686e-009
> 
> 
> Hth, regards
> Andres