Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: efficient way to read this text file

Subject: efficient way to read this text file

From: Varun

Date: 11 Aug, 2007 16:45:03

Message: 1 of 5

Hi,

I would like to read data from a text file that has the
following content:

TITLE="H:, "U m/s", "V m/s", "CHC", ZONE T="83.941605 um/p,
2.014599, 83.270073, 9900000256.000000, 9900000256.000000, -1
2.686131, 83.270073, 9900000256.000000, 9900000256.000000, -1
3.357664, 83.270073, 9900000256.000000, 9900000256.000000, -1
4.029197, 83.270073, 9900000256.000000, 9900000256.000000, -1
75.883209, 44.992699, 0.026952, 0.018204, 4


Is there an efficient way to read just the numbers after the
first line into a [m,n] matrix.

Regards,
Varun

Subject: Re: efficient way to read this text file

From: us

Date: 12 Aug, 2007 09:42:13

Message: 2 of 5

Varun:
<SNIP importing formatted text evergreen...

> Is there an efficient way to read just the numbers after
the first line into a [m,n] matrix...

one of the many solutions

% assume your data is in <foo.txt>
     fnam='foo.txt';
     m=dlmread(fnam,',',1,0);

Subject: Re: efficient way to read this text file

From: Varun

Date: 13 Aug, 2007 22:53:15

Message: 3 of 5

thank you, that worked

varun

"us " <us@neurol.unizh.ch> wrote in message
<f9mkll$3hr$1@fred.mathworks.com>...
> Varun:
> <SNIP importing formatted text evergreen...
>
> > Is there an efficient way to read just the numbers after
> the first line into a [m,n] matrix...
>
> one of the many solutions
>
> % assume your data is in <foo.txt>
> fnam='foo.txt';
> m=dlmread(fnam,',',1,0);

Subject: Problem regarding data analysis containing string in the file

From: edward kabanyas

Date: 12 Feb, 2008 16:02:02

Message: 4 of 5

Dear All,
I have problem in reading file containing string or
character in my file. The following are the data example:

11:48:00 -> 11:49:00 0.00 -> 0.25 mm n= 0.0000000 /m3mm
11:48:00 -> 11:49:00 0.25 -> 0.50 mm n= 0.0000000 /m3mm
11:48:00 -> 11:49:00 0.50 -> 0.75 mm n= 0.0000000 /m3mm
11:48:00 -> 11:49:00 0.75 -> 1.00 mm n= 1.8491934 /m3mm
rainrate =0.001686 mm/hr
11:49:00 -> 11:50:00 0.00 -> 0.25 mm n= 0.0000000 /m3mm
11:49:00 -> 11:50:00 0.25 -> 0.50 mm n= 0.0000000 /m3mm
11:49:00 -> 11:50:00 0.50 -> 0.75 mm n= 2.6686186 /m3mm
11:49:00 -> 11:50:00 0.75 -> 1.00 mm n= 0.0000000 /m3mm
rainrate =0.000455 mm/hr
11:50:00 -> 11:51:00 0.00 -> 0.25 mm n= 0.0000000 /m3mm
11:50:00 -> 11:51:00 0.25 -> 0.50 mm n= 0.0000000 /m3mm
11:50:00 -> 11:51:00 0.50 -> 0.75 mm n= 2.3139154 /m3mm
11:50:00 -> 11:51:00 0.75 -> 1.00 mm n= 3.5420286 /m3mm
rainrate =0.004181 mm/hr

Desired new file structure:
11:48:00 0.0000000 0.0000000 0.0000000 1.8491934 0.001686
11:49:00 0.0000000 0.0000000 2.6686186 0.0000000 0.000455
11:50:00 0.0000000 0.0000000 2.3139154 3.5420286 0.004181

I really need your help. I want to pick the value of last
coulumn (value of after n), rainrate value and time only and
putting them in new file with structure as desired new file.

That's my question, thanks very much for your best help

Best regards;
Edward

Subject: Re: Problem regarding data analysis containing string in the file

From: Arthur G

Date: 12 Feb, 2008 17:38:06

Message: 5 of 5

On Tue, 12 Feb 2008 11:02:02 -0500, edward kabanyas <djuky_hmi@yahoo.com=
> =

wrote:
> Dear All,
> I have problem in reading file containing string or
> character in my file. The following are the data example:
>
> 11:48:00 -> 11:49:00 0.00 -> 0.25 mm n=3D 0.0000000 /m3mm
> 11:48:00 -> 11:49:00 0.25 -> 0.50 mm n=3D 0.0000000 /m3mm
> 11:48:00 -> 11:49:00 0.50 -> 0.75 mm n=3D 0.0000000 /m3mm
> 11:48:00 -> 11:49:00 0.75 -> 1.00 mm n=3D 1.8491934 /m3mm
> rainrate =3D0.001686 mm/hr
> 11:49:00 -> 11:50:00 0.00 -> 0.25 mm n=3D 0.0000000 /m3mm
> 11:49:00 -> 11:50:00 0.25 -> 0.50 mm n=3D 0.0000000 /m3mm
> 11:49:00 -> 11:50:00 0.50 -> 0.75 mm n=3D 2.6686186 /m3mm
> 11:49:00 -> 11:50:00 0.75 -> 1.00 mm n=3D 0.0000000 /m3mm
> rainrate =3D0.000455 mm/hr
> 11:50:00 -> 11:51:00 0.00 -> 0.25 mm n=3D 0.0000000 /m3mm
> 11:50:00 -> 11:51:00 0.25 -> 0.50 mm n=3D 0.0000000 /m3mm
> 11:50:00 -> 11:51:00 0.50 -> 0.75 mm n=3D 2.3139154 /m3mm
> 11:50:00 -> 11:51:00 0.75 -> 1.00 mm n=3D 3.5420286 /m3mm
> rainrate =3D0.004181 mm/hr
>
> Desired new file structure:
> 11:48:00 0.0000000 0.0000000 0.0000000 1.8491934 0.001686
> 11:49:00 0.0000000 0.0000000 2.6686186 0.0000000 0.000455
> 11:50:00 0.0000000 0.0000000 2.3139154 3.5420286 0.004181
>
> I really need your help. I want to pick the value of last
> coulumn (value of after n), rainrate value and time only and
> putting them in new file with structure as desired new file.
>
> That's my question, thanks very much for your best help
>
> Best regards;
> Edward
>

If you didn't have two "kinds" of lines, textscan would be helpful.

But it sounds to me like you'll have to "manually" open the file,
read it line by line, and find the last number in each line, e.g.
use the following functions:

fopen to open the file
fgetl to read a line
sscanf or other string functions to parse the line
fclose to close the file

--Arthur

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
string reading in text file edward kabanyas 12 Feb, 2008 11:05:07
evergreen us 30 Jan, 2008 20:30:13
code us 12 Aug, 2007 05:45:07
file io us 12 Aug, 2007 05:45:07
dlmread us 12 Aug, 2007 05:45:07
text read Varun 11 Aug, 2007 12:45:07
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics