Thread Subject: reading txt

Subject: reading txt

From: Luigi Giaccari

Date: 22 Jan, 2009 17:44:02

Message: 1 of 4

HI i am looking for a way to count numbers of lines in a txt files. This should be usefful to estimate the number of points and preallocate arrays to store data. Thank you

Subject: reading txt

From: checkmate

Date: 22 Jan, 2009 17:49:41

Message: 2 of 4

On Jan 22, 9:44=A0am, "Luigi Giaccari" <giaccarilu...@msn.com> wrote:
> HI i am looking for a way to count numbers of lines in a txt files. This =
should be usefful to estimate the number of points and preallocate arrays t=
o store data. Thank you

I'm not sure if you need to estimate the number of points and
preallocate the arrays to store the data in order to load the text
file somewhere.

load textname.txt

loads whatever you have in the text file to a matrix already. size
(textname) would return the number of columns and rows you have in the
text file.

Subject: reading txt

From: Walter Roberson

Date: 22 Jan, 2009 18:02:54

Message: 3 of 4

Luigi Giaccari wrote:
> HI i am looking for a way to count numbers of lines in a txt files. This should be usefful
> to estimate the number of points and preallocate arrays to store data. Thank you

There is no Matlab-provided function to count the number of lines in a file.
The code for counting the number of lines more or less comes down to

while true
  ALine = read a line
  if ALine indicates end of file, break out of the loop
  increment line counter
end


Or here is an approximation that counts the number of non-empty lines in a text file:

length(textread(THEFILENAME, '%*[^\n]%c'))

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: reading txt

From: Luigi Giaccari

Date: 22 Jan, 2009 18:07:03

Message: 4 of 4

Thank you very much

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
reading txt Luigi Giaccari 22 Jan, 2009 12:46:59
rssFeed for this Thread

Contact us at files@mathworks.com