Thread Subject: reading a .txt file with dates

Subject: reading a .txt file with dates

From: ALEKSANDER

Date: 3 Aug, 2008 18:05:04

Message: 1 of 2

Hi!

I've got a file in this form:
dd/mm/yy [integer]

The first lines of my file (result.txt):
30/07/08 161
31/07/08 150
01/08/08 151
05/08/08 160

And I wish to generate two vectors: x(n) with n as the n'th
line in the file, with the dates in the form "datenum", and
the other offcourse y(n) with the corresponding numbers.

to make it all crystall clear:
x(1) = datenum(20/07/08) %this is wrong,but u get the idea!
y(1) = 161
...etc

If the format of the file is difficult to read, I can
easily change it, it's matlab-genrated.

Thanks!
Aleksander, Norway

Subject: reading a .txt file with dates

From: Andres

Date: 3 Aug, 2008 19:52:01

Message: 2 of 2

"ALEKSANDER " <aleksander.rise.gallala@gmail.com> wrote in
message <g74s0g$j2h$1@fred.mathworks.com>...
> Hi!
>
> I've got a file in this form:
> dd/mm/yy [integer]
>
> The first lines of my file (result.txt):
> 30/07/08 161
> 31/07/08 150
> 01/08/08 151
> 05/08/08 160
>
> And I wish to generate two vectors: x(n) with n as the n'th
> line in the file, with the dates in the form "datenum", and
> the other offcourse y(n) with the corresponding numbers.
>
> to make it all crystall clear:
> x(1) = datenum(20/07/08) %this is wrong,but u get the idea!
> y(1) = 161
> ...etc
>
> If the format of the file is difficult to read, I can
> easily change it, it's matlab-genrated.
>
> Thanks!
> Aleksander, Norway

The file format is easy to read, by humans and by matlab :-)
Obviously, get the plain numbers first, e.g. using textscan
(you only need to tell textscan that '/' should be treated
as a whitespace - look for the 'Whitespace' parameter in the
doc), and then feed datenum with the properly arranged
numbers, x = datenum(Y, M, D)
regards
Andres

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com