Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe13.iad.POSTED!7564ea0f!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: textscan - 2 rows of data per record
References: <gpego5$n8k$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-DAA396.23405013032009@news.frontiernet.net>
Lines: 55
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Sat, 14 Mar 2009 03:40:51 UTC
Organization: Frontier
Date: Fri, 13 Mar 2009 23:40:50 -0400
Xref: news.mathworks.com comp.soft-sys.matlab:524787


In article <gpego5$n8k$1@fred.mathworks.com>,
 "Pete sherer" <tsh@abg.com> wrote:

> I have a text file that each data contains 2 rows of information
> 900,id,name,age,height,sex
> 901,weight,occupation
> 
> Example:
> 
> 900,1,Jim,60,175,male
> 901,150,none
> 900,2,Paul,30,190,male
> 901,233,engineer
> 
> With this non-uniform data, can I use TEXTSCAN to read the data above?

Yes, with something like this:

>> fid = fopen('pete.dat');
>> c = textscan(fid,'%*n%n%s%n%n%s%*n%n%s',...
'Delimiter',',\n','Whitespace','');
>> fclose(fid);
>> c{1}
ans =
     1
     2
>> c{2}
ans = 
    'Jim'
    'Paul'
>> c{3}
ans =
    60
    30
>> c{4}
ans =
   175
   190
>> c{5}
ans = 
    'male'
    'male'
>> c{6}
ans =
   150
   233
>> c{7}
ans = 
    'none'
    'engineer'

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.