[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem using sscanf
From: |
CdeMills |
Subject: |
Re: Problem using sscanf |
Date: |
Mon, 28 Nov 2011 03:33:52 -0800 (PST) |
Could you try:
Fritz Fischer wrote
>
> Hello,
>
> I am trying to change some MatLab code that reads epw-weather files to
> work
> with Octave
> and I need to replace the textread() function with sscanf() or fscanf().
>
> But I can't figure out the correct syntax.
>
> The lines that have to be read look like this:
>
> 1986,1,1,18,60,A7A7E8A7*0H5H5H5I5I5I5I5A7A7E9E9A7*0F86F9?9?,22.0,20.0,88,89500,399,1414,391,170,110
>
> I tried the following syntax:
>
> sscanf(loc, '%i,%i,%i,%i,%i,%s,%f\n')
>
> This correctly reads the first fife entries:
>
> but the following fields in the array are the ASCII-numbers of the cryptic
> string part and after this the floating point
> numner 22.0, supposed to be read with %f does not show up..
>
> Can someone of you tell me what I am doing wrong?
>
> Kind regards,
>
>
The match is greedy, meaning once you put a %s format, it 'eats up'
everything. You better split first into fields:
content = strsplit( loc, ',')
wil return a cell array of strings; convert them with str2num afterwards.
Now if you want direct conversion, you can use:
content = cellfun(@(x) str2num(x), strsplit(loc, ','), 'UniformOutput',
false);
to get an all-numeric result, except for the town name, which will result in
an empty numeric value.
HTH
Pascal
--
View this message in context:
http://octave.1599824.n4.nabble.com/Problem-using-sscanf-tp4114742p4114901.html
Sent from the Octave - General mailing list archive at Nabble.com.