|
"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
|