The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Pull out specific numbers from unstructured text file
Replies: 13   Last Post: Aug 8, 2014 6:51 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 9,850
Registered: 6/7/07
Re: Pull out specific numbers from unstructured text file
Posted: Feb 9, 2013 5:38 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/9/2013 3:50 PM, dpb wrote:
> On 2/9/2013 1:12 PM, Stan wrote:
>> ^^^^^Okay I think I don't understand Lines 5,7,8 in your shortcut code:
>> Line 1: > fid=fopen(....,'rt');
>> Line 2: > l=' ';
>> Line 3: > while 1
>> Line 4: > l=fgetl(fid);
>> Line 5: > if strfind(l,'Nmoves')>0,break,end
>> Line 6: > end
>> Line 7: > Nmoves=sscanf(l,'Nmoves=%d');
>> Line 8: > Nrequired=fscanf(fid,'Nrequired=%d');
>> Line 9: > fid=fclose(fid);


>> Questions:
>> In line 8, why did you change from l to fid?


> You still don't seem to grasp that the fgetl() reads a record including
> the \n (newline) and returned that in the character variable 'l' and the
> first sscanf() is parsing that string--nothing else has happened in the
> file at that point (after the sscanf() that is). _THEN_, we went back to
> the file and got as much of the next record as required to get the next
> variable by the use of fscanf().


Also intended to point out explicitly you're seeming to overlook that
fgetl() uses fid to get l -- the same fid as in fscanf(). One has to
read the file one place or the other--in one case it isn't being parsed
simply characters stored whereas the other is converting to numeric
internal form for a given format while reading...


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.