Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
how to fgetl and sscanf numbers only
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
summer8  
View profile  
 More options Sep 24 2012, 5:17 am
Newsgroups: comp.soft-sys.matlab
From: "summer8 " <sumi_r...@hotmail.com>
Date: Mon, 24 Sep 2012 09:17:09 +0000 (UTC)
Local: Mon, Sep 24 2012 5:17 am
Subject: how to fgetl and sscanf numbers only

Hi,
I'm trying to read the numbers only from each line but without reading the ND or the commas.

ND, 1,      -0.0104594     -0.12456164  6.0715322E-017
ND, 2,   -0.0098119825     -0.12460658   -0.0013874772
ND, 3,   -0.0096356887     -0.11458401    -0.001629882

With the numbers read, is it possible to sscanf them into another textfile and place the read numbers in this structure format?

<node id="1">-0.0104594,-0.12456164,6.0715322E-017</node>
<node id="2"> -0.0098119825,-0.12460658,-0.0013874772</node>
<node id="3">0.0096356887,-0.11458401,-0.001629882 </node>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dpb  
View profile  
 More options Sep 24 2012, 10:00 am
Newsgroups: comp.soft-sys.matlab
From: dpb <n...@non.net>
Date: Mon, 24 Sep 2012 09:00:11 -0500
Local: Mon, Sep 24 2012 10:00 am
Subject: Re: how to fgetl and sscanf numbers only
On 9/24/2012 4:17 AM, summer8 wrote:

> Hi, I'm trying to read the numbers only from each line but without
> reading the ND or the commas.
> ND, 1, -0.0104594 -0.12456164 6.0715322E-017
> ND, 2, -0.0098119825 -0.12460658 -0.0013874772
> ND, 3, -0.0096356887 -0.11458401 -0.001629882

> With the numbers read, is it possible to sscanf them into another
> textfile and place the read numbers in this structure format?
> <node id="1">-0.0104594,-0.12456164,6.0715322E-017</node>
> <node id="2"> -0.0098119825,-0.12460658,-0.0013874772</node>
> <node id="3">0.0096356887,-0.11458401,-0.001629882 </node>

Use textscan() w/ 'delimiter',',' and skip the first field or use the
'treatasempty' parameter.

--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dpb  
View profile  
 More options Sep 24 2012, 12:40 pm
Newsgroups: comp.soft-sys.matlab
From: dpb <n...@non.net>
Date: Mon, 24 Sep 2012 11:40:40 -0500
Local: Mon, Sep 24 2012 12:40 pm
Subject: Re: how to fgetl and sscanf numbers only
On 9/24/2012 9:00 AM, dpb wrote:

...

Or, just go straightahead w/ fscanf/fprintf...

 >> c={'ND, 1,      -0.0104594     -0.12456164  6.0715322E-017';
'ND, 2,   -0.0098119825     -0.12460658   -0.0013874772';
'ND, 3,   -0.0096356887     -0.11458401    -0.001629882'};
 >> reshape(sscanf(char(c)','ND, %d, %f %f %f'),4,[])'
ans =
     1.0000   -0.0105   -0.1246    0.0000
     2.0000   -0.0098   -0.1246   -0.0014
     3.0000   -0.0096   -0.1146   -0.0016
 >> fprintf('<node id="%d">%f,%f,%f</node>\n',ans')
<node id="1">-0.010459,-0.124562,0.000000</node>
<node id="2">-0.009812,-0.124607,-0.001387</node>
<node id="3">-0.009636,-0.114584,-0.001630</node>
 >>

Salt to suit...NB the locations of the transpose operator...

--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »