Thread Subject: Read a txt-file with dates?

Subject: Read a txt-file with dates?

From: Erik Andersson

Date: 6 May, 2008 13:36:04

Message: 1 of 6

Hello!
I'got a problem reading my .txt file which looks like this:

20070830 1840 3.79 2.87 271.40
20070830 1850 6.40 0.42 269.90
20070830 1900 6.56 0.51 269.90

I've tried textread('test.txt','%d%d%f%f%f',' ').

What do I have to change to make it work?

Subject: Read a txt-file with dates?

From: Bob

Date: 6 May, 2008 14:11:03

Message: 2 of 6

Does this help?

[yyyymmdd,hhmm,x1,x2,x3] = textread('test.txt','%d %d %f %f %f');

Cheers
Bob

Subject: Read a txt-file with dates?

From: Erik Andersson

Date: 6 May, 2008 14:24:03

Message: 3 of 6

Bob <rbemis@mathworks.com> wrote in message <46e1b4d8-033b-
46d2-8d20-c0757fc5992c@x35g2000hsb.googlegroups.com>...
> Does this help?
>
> [yyyymmdd,hhmm,x1,x2,x3] = textread('test.txt','%d %d %f
%f %f');
>
> Cheers
> Bob

It still doesn't work, i get the following error:

??? Trouble reading integer from file (row 2, field 2)
==> .87 271.40\n

Error in ==> textread at 176
[varargout{1:nlhs}]=dataread('file',varargin{:});

Error in ==> importeradata at 2
[yyyymmdd,hhmm,x1,x2,x3] = textread('test.txt','%d %d %f %f
%f');

What does this mean and what should be corrected??

Subject: Read a txt-file with dates?

From: Erik Andersson

Date: 6 May, 2008 14:37:03

Message: 4 of 6

I got it to work now, thanks!

Subject: Read a txt-file with dates?

From: Erik Andersson

Date: 6 May, 2008 14:40:18

Message: 5 of 6

Is it possible to get the outcome as a matrix where the
colums are V=[year time x1 x2 x3]. Now I just get seperate
vectors. If I put the togheter as a matrix as defined above
a get the following:

V =

  1.0e+007 *

    2.0071 0.0002 0.0000 0.0000 0.0000
    2.0071 0.0002 0.0000 0.0000 0.0000
    2.0071 0.0002 0.0000 0.0000 0.0000
    2.0071 0.0002 0.0000 0.0000 0.0000

Subject: Read a txt-file with dates?

From: Bob

Date: 6 May, 2008 18:23:47

Message: 6 of 6

You mean like this?

[x(:,1) x(:,2) x(:,3) x(:,4) x(:,5)] = textread('test.txt','%d %d %f
%f %f');

Cheers
Bob

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

Public Submission Policy

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 Disclaimer prior to use.

Contact us at files@mathworks.com