Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!i76g2000hsf.googlegroups.com!not-for-mail
From: boivie@gmail.com
Newsgroups: comp.soft-sys.matlab
Subject: Re: read multi-line data with multiple delimiters
Date: Fri, 24 Oct 2008 12:43:28 -0700 (PDT)
Organization: http://groups.google.com
Lines: 56
Message-ID: <477251cf-9768-492a-859c-4d1c3f1193f3@i76g2000hsf.googlegroups.com>
References: <70d4e42d-48e0-4f97-a9d2-83aa4eeed8c2@l76g2000hse.googlegroups.com> 
	<f1e9e1ed-edaf-48ae-a90f-7112075ab1b6@64g2000hsu.googlegroups.com>
NNTP-Posting-Host: 129.236.20.54
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1224877408 30531 127.0.0.1 (24 Oct 2008 19:43:28 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 24 Oct 2008 19:43:28 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: i76g2000hsf.googlegroups.com; posting-host=129.236.20.54; 
	posting-account=n_evDQoAAACGu2lqvH-6uLNULp4evcXV
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) 
	Gecko/2008092417 Firefox/3.0.3,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:497155


On Oct 24, 11:23=A0am, Rune Allnor <all...@tele.ntnu.no> wrote:
> 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 hasdata(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
> > delimiteddataassociated with that header. =A0I seem to be able to
> > extract the first line ofdatausing textscan with comma as the
> > delimiter. =A0Using regexp, I have gotten both lines ofdata, 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 twodatalines.
> Just remember that you read eachdataline one at the
> time and need to store the correspondingdatasomewhere.
>
> The basic program would go something like (pseudocode!)
>
> while (~feof(fid))
> =A0 =A0while (~regexpmatch('tie'|'line'))
> =A0 =A0 =A0 s =3D fgetl(fid)
> =A0 =A0end
> =A0 =A0extract number from present line that contains
> =A0 =A0'tie' or 'line'
> =A0 =A0s =3D fgetl(fid)
> =A0 =A0A =3D sscanf(s,'%f,%f,%f,%f');
> =A0 =A0s =3D fgetl(fid)
> =A0 =A0B =3D sscanf(s,'%f,%f,%f,%f');
> =A0 =A0store A and B wherever they need to go
> end
>
> Rune

Rune,

Thanks very much for the help.  I'm getting an error using the OR
operator '|' in this line: while (~regexpmatch('Tie'|'Line')).
Matlab returns:
  'Error using =3D=3D> or
  Inputs must have the same size.'

I tried a few things, including using '||' instead of '|', and
breaking it up into two parts: 'while (~regexpmatch('Tie') &&
~regexpmatch('Line'))'

Neither has worked.  Any suggestions?  Thanks.

Ethan