Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6915
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: how to get string in sci. notation to a number? |
| Date | 2011-12-03 10:09 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jbcsgs$bvv$1@smc.vnet.net> (permalink) |
On 12/2/11 at 7:21 AM, ralph.dratman@gmail.com (Ralph Dratman) wrote:
>But that is so easy with pattern replacement. More experienced
>people will surely manage it without using StringReplace, but I get
>flummoxed on which kind of Hold to use.
>In[652]:= flpnumsStr =
>ToString[{{"4.998865e+000", "9.564453e-006"}, {"5.630450e+000",
>"9.194384e-006"}, {"6.113276e+000", "8.134170e-006"}}]
>Out[652]= "{{4.998865e+000, 9.564453e-006}, {5.630450e+000,
>9.194384e-006}, {6.113276e+000, 8.134170e-006}}"
>In[653]:= ToExpression[StringReplace[flpnumsStr, "e" -> "*10^"]]
>Out[653]= {{4.99887, 9.56445*10^-6}, {5.63045,
>9.19438*10^-6}, {6.11328, 8.13417*10^-6}}
I assume you really didn't manually enter the strings in the
form of Mathematica lists. So, let me start by putting the
output of your ToString above into something that likely
resembles the original data, i.e.,
In[5]:= p =
StringReplace[
StringTake[
ToString[{{"4.998865e+000", "9.564453e-006"}, {"5.630450e+000",
"9.194384e-006"}, {"6.113276e+000",
"8.134170e-006"}}], {3, -3}], "}, {" -> "\n"]
Out[5]= 4.998865e+000, 9.564453e-006
5.630450e+000, 9.194384e-006
6.113276e+000, 8.134170e-006
Now, these can be read in as numbers simply by using ImportString
In[6]:= ImportString[p, "CSV"]
Out[6]= {{4.998865, 9.564453*^-6}, {5.63045, 9.194384*^-6},
{6.113276, 8.13417*^-6}}
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: how to get string in sci. notation to a number? Bill Rowe <readnews@sbcglobal.net> - 2011-12-03 10:09 +0000
csiph-web