3
$\begingroup$

How to replace the E with scientific notation *^?

{0.1971468 E - 001, 0.1422880 E - 001, 0.2046836 E - 001, 
      0.1394519 E - 001, -0.9795244 E - 002, 0.1424443 E - 001} /. E -> *^
$\endgroup$
  • 3
    $\begingroup$ Where does this data come from? That's certainly not Mathematica syntax for expressing scientific notation. Did it come as a string? $\endgroup$ – b3m2a1 Dec 21 '19 at 9:16
  • 1
    $\begingroup$ it's a TextPad data imported into Mathematica $\endgroup$ – acoustics Dec 21 '19 at 9:18
  • $\begingroup$ StringReplace["{0.1971468 E-001,0.1422880 E-001,0.2046836 \ E-001,0.1394519 E-001,-0.9795244 E-002,0.1424443 E-001}", "E" -> "*^"] $\endgroup$ – Xminer Dec 21 '19 at 9:18
  • $\begingroup$ How'd you import it? Copy paste? $\endgroup$ – b3m2a1 Dec 21 '19 at 9:18
  • 3
    $\begingroup$ I'd say "How to replace E?" is the wrong question. The right question would be: how to import that data? It's hard to tell without seeing your datafile, but most likely Import[..., "Table"]. $\endgroup$ – Szabolcs Dec 21 '19 at 18:45
4
$\begingroup$
a = Import["modeshapes_evolution.txt", "Lines"];
b = StringSplit[a, ","];
c = StringReplace[#, "E - " -> "*10^-"] &  /@ b;
data = ToExpression[c]

The above works on a text file with lines that contain your sample data.

Better method:

To use MMA's built-in data format conversion, as suggested by @Roman, you could simply remove the spaces and read the text as data:

s = Import["modeshapes_evolution.txt", "String"];
data = ImportString[StringReplace[s, " " -> ""], "Data"]
$\endgroup$
2
$\begingroup$

The input as a string (maybe read from a file):

S = "{0.1971468 E - 001, 0.1422880 E - 001, 0.2046836 E - 001,
      0.1394519 E - 001, -0.9795244 E - 002, 0.1424443 E - 001}";

Delete whitespace and curly braces, then import as CSV:

ImportString[StringDelete[S, "{" | "}" | " " | "\n"], "CSV"]
(*    {{0.0197147, 0.0142288, 0.0204684, 0.0139452, -0.00979524, 0.0142444}}    *)

From the documentation: "Import automatically recognizes common number formats, including C and Fortran notations."

Maybe it's enough to import your entire file as CSV instead of as Text.

$\endgroup$
0
$\begingroup$

In Mathematica 12 both do not work

(i) direct input of the given list,

(ii) first enter = and then the list

because all suppress or ignore the E.

Just in the expansion of the link "Show all solution" the E is identified.

The solution is the step suggested by Xminer after entering the = for the Wolfram Alpha type of input interpretation and 10 instead of *. The trick is not to enter

StringReplace["{0.1971468 E-001,0.1422880 E-001,0.2046836 \ E-001,0.1394519 E-001,-0.9795244 E-002,0.1424443 E-001}","E"->" 10^"]

direct in the = line, but to copy and paste the outputenter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.