Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

No tags are associated with this thread.

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.

Contact us