Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!64g2000hsu.googlegroups.com!not-for-mail
From: Rune Allnor <allnor@tele.ntnu.no>
Newsgroups: comp.soft-sys.matlab
Subject: Re: read multi-line data with multiple delimiters
Date: Fri, 24 Oct 2008 08:23:07 -0700 (PDT)
Organization: http://groups.google.com
Lines: 38
Message-ID: <f1e9e1ed-edaf-48ae-a90f-7112075ab1b6@64g2000hsu.googlegroups.com>
References: <70d4e42d-48e0-4f97-a9d2-83aa4eeed8c2@l76g2000hse.googlegroups.com>
NNTP-Posting-Host: 77.17.24.172
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1224861787 12910 127.0.0.1 (24 Oct 2008 15:23:07 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 24 Oct 2008 15:23:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 64g2000hsu.googlegroups.com; posting-host=77.17.24.172; 
	posting-account=VAp5gAkAAAAmkCze5hvZtMeedpZWNthI
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
	CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:497118


On 24 Okt, 17:04, boi...@gmail.com wrote:
> Hi all - I've scoured the net and mathworks and haven't come across
> how to solve this. =A0I haven't used Matlab in quite a while, and it
> seems like this shouldn't be very hard, but I haven't managed to get
> this yet.
>
> The file I am reading in has data (after several file header lines)
> that consists of one line of header info ("Line" or "Tie" and the
> number - both of which I need to extract) and two lines of comma
> delimited data associated with that header. =A0I seem to be able to
> extract the first line of data using textscan with comma as the
> delimiter. =A0Using regexp, I have gotten both lines of data, but as 4
> variables, rather than 8. =A0Any pointers or code help would be much
> appreciated. =A0Thanks.

It seems you are almost there. REGEXP is the method
I would use to detect the header lines. However,
you might want to use SSCANF to read the two data lines.
Just remember that you read each data line one at the
time and need to store the corresponding data somewhere.

The basic program would go something like (pseudocode!)

while (~feof(fid))
   while (~regexpmatch('tie'|'line'))
      s =3D fgetl(fid)
   end
   extract number from present line that contains
   'tie' or 'line'
   s =3D fgetl(fid)
   A =3D sscanf(s,'%f,%f,%f,%f');
   s =3D fgetl(fid)
   B =3D sscanf(s,'%f,%f,%f,%f');
   store A and B wherever they need to go
end

Rune