Got Questions? Get Answers.
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:
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: 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: 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: 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

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