Thread Subject: textscan - 2 rows of data per record

Subject: textscan - 2 rows of data per record

From: Pete sherer

Date: 13 Mar, 2009 20:47:01

Message: 1 of 2

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?

Subject: textscan - 2 rows of data per record

From: Doug Schwarz

Date: 14 Mar, 2009 03:40:50

Message: 2 of 2

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.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com