|
On Nov 9, 1:00 pm, "Jon Shultz" <jjddshu...@yahoo.com> wrote:
> Rune Allnor <all...@tele.ntnu.no> wrote in message <dfca570a-9e21-4622-bdea-69768c9d2...@p8g2000yqb.googlegroups.com>...
> > On 8 Nov, 20:24, "Jon Shultz" <jjddshu...@yahoo.com> wrote:
> > > I'm trying to read in a datafile that's really big (>2GB) in sections that are a couple hundred thousand lines long each. ?I need to know how many lines are in the parent file first. ?
>
> > > I have a routine now that does it like this:
> > > totlines=0;
> > > while ~feof(fid)
> > > ? ? line=fgetl(fid);
> > > ? ? totlines=totlines+1;
> > > end
>
> > > This does well with the memory part, but takes forever. ?There has got to be a more efficient way to do this, but I'm stuck.
>
> > Read the file in larger batches than a single line.
>
> > Rune
>
> Thank you. I am using textscan to get the data blocks in the code which follows what I have written above. Let me restate my question. Is there a way to determine the number of lines in a large file without reading in the data (which will crash Matlab)?
>
> I want to use the total number of lines to determine the best way to segment the files.
>
> Jon
Copy and paste these lines into a new file called CountLines.pl in
Matlab's path:
while (<>) {};
print $.,"\n";
Now, run it in Matlab like this:
perl('CountLines.pl',filename)
where filename is your file name.
|