Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: reading date_time in PM/AM format from an ascii file
Date: Mon, 30 Jun 2008 10:54:01 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 56
Message-ID: <g4ae09$s37$1@fred.mathworks.com>
References: <g473ot$er2$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1214823241 28775 172.30.248.38 (30 Jun 2008 10:54:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 30 Jun 2008 10:54:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:476590



"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.
> [..]



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