help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read file, given a non-octave header


From: Thomas Treichl
Subject: Re: read file, given a non-octave header
Date: Sat, 27 Jan 2007 18:52:27 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)

the_verge schrieb:
Thomas,

Thanks for addressing my questions.  I'm really close to making it read
properly, but I'm having a small problem:  The first row in my cell array is
always the 3rd line of the file, regardless of whether it is a comment line
or a line of data.  For some reason Octave doesn't seem to be ignoring the
comments.  The reason it begins reading on the 3rd line is because of the
fgetl(fid); fgetl(fid); that you put in there to ignore the descriptor
lines.  Preferably, it would skip all 35 or so lines of comments, and then
skip the two data description lines, and then begin reading from the first
line of data.

Any ideas on how to make it skip comment lines (preceded by a #)?

Thanks,
Vergil

P.S. For reference, when I called the function that you wrote for me, here
was my resulting cell array (you can see the description lines in there):
...

Try this

   function vret = parsedata (filename)
     [vfid, vmsg] = fopen (filename, "r");
     if (isempty (vmsg) == false), error (vmsg); endif

     vcnt = 1;             # Initialize counter for while loop
     vstr = fgetl (vfid);  # Get first line of data file
     while (vstr != -1)
       if (vstr(1) != "#") # Ignore every that starts with '#'
         [vret{vcnt,1}, vret{vcnt,2}, vret{vcnt,3}, vret{vcnt,4}, \
          vret{vcnt,5}, vret{vcnt,6}, vret{vcnt,7}] = \
            sscanf (vstr, "%s\t%s\t%s\t%s\t%s\t%s\t%s", "C");
         vcnt = vcnt + 1;
       endif
       vstr = fgetl (vfid);
     endwhile

     fclose (vfid);
   endfunction

and copy the parsed data into a new variable if you don't like the two describtion lines:

  newdata = olddata{3:end,:}

Thomas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]