help-octave
[Top][All Lists]
Advanced

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

Re: Specific fixed width question...


From: Judd Storrs
Subject: Re: Specific fixed width question...
Date: Tue, 14 Sep 2010 15:17:54 -0400

On Tue, Sep 14, 2010 at 12:41 PM, fork <address@hidden> wrote:
> Two lines of example data (notice that the county field (#4) is 25 characters
> wide and that spaces are used both between fields like WA and 053 and between
> parts of the county name, so you can't just split on spaces):
>
> WA 053 011 Clark County             45
> WA 053 027 Grays Harbor County      100
>
> I would like to parse out cntys=[11; 27] and data=[45; 100] from the above.

sscanf can extract formatted text well. e.g.:

sscanf("WA 053 011 Clark County             45","%*2c %*3d %3d %*25c %d")
sscanf("WA 053 027 Grays Harbor County      100,"%*2c %*3d %3d %*25c %d")

You can use fscanf to read the whole file:

fid = fopen("data.txt") ;
data = fscanf(fid,"%*2c %*3d %3d %*25c %d\n",[2,inf]) ;
fclose(fid) ;
cntys = data(1,:).' ;
data = data(2,:).' ;


--judd



reply via email to

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