I wish to export a matrix of real numbers out to a txt file in which the entries have the MatLab form:


Code Export["out.txt", ScientificForm[out,19,NumberFormat->(Row[{#1,"e",#3}]&)], "Table"]; doesn't do what I want. How can I remedy this?


Thanks to andre314 for providing the link and avni for the code in this post, the solution is:

Eform[x_?NumericQ,d_:18]:=Module[{m,e,mm,ee}, {m,e}=MantissaExponent[x+0.0];m=m*10; 
If[m!=0,e=e-1,m=0.]; e=Clip[e,{-99,99}]; mm=ToString[PaddedForm[m,{d+1,d}]]; 
ee=If[-10<e<10,"0",""]<>ToString[Abs@e]; StringJoin[mm,If[e<0,"e-","e+"],ee]];


(I thought there would be an easier, i.e. already built-in function for this, that's why I asked.)

  • 1
    $\begingroup$ Carl Woll’s answer is much simpler and probably faster. I’d give that one a try too. $\endgroup$ – b3m2a1 Jun 11 '19 at 7:08

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.