MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Writing to an External file, ie .txt

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90823] Re: Writing to an External file, ie .txt
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 25 Jul 2008 06:16:41 -0400 (EDT)
  • References: <g56ti4$41a$1@smc.vnet.net>

On Thu, Jul 24, 2008 at 5:35 PM, DAVID FOURIE wrote:

<snip>

> My output is generating curly parenthesies around it "{}".
>
> I am expoting it with the code:
>
>        mkw = Table[0, {time - 1}, {2}];
>        For[w = 1, w < (time), mkw[[w, 2]] = v[w] /. solution; w++];
>        For[w = 1, w < (time), mkw[[w, 1]] = w; w++];
>
>        mkw;
>        Export[saveFilesAB[[i]], mkw, "Table"];
>
> In the export file the data looks like this:
>
>        1   {-79.84700975294606}
>        2   {-79.69051240690148}
>        3   {-79.53102986953975}
>        4   {-79.36900699034439}
>        5   {-79.20482318524301}
>        6   {-79.03880245505214}
>        7   {-78.87122188515096}
>        8   {-78.70231884148791}
>        9   {-78.53229705609004}
>        10   {-78.36133171685125}
>        11   {-78.18957405806462}
>        12   {-78.01715486892012}
>        13   {-77.84418733157375}
>        14   {-77.6707702358632}
>        15   {-77.49698984909358}
>        16   {-77.32292183143544}
>        17   {-77.148632902709}
>        18   {-76.97418220274439}
>        19   {-76.7996223969284}
>        20   {-76.62500065712533}
>
> I have tried different export style but it can't get rid of it. Is this something to do with using .solution?
>
> My data analysis requires this format but can't handle the {} so I am stuck with out passing it though a java script that will remove them.

<snip>

[... Crossposted to MathGroup ...]

A quick fix would be:

    mkw[[All, 2]] = Flatten[mkw[[All, 2]]]

For instance,

    [...]

    In[12]:= mkw = Table[0, {time - 1}, {2}];
    For[w = 1, w < (time), mkw[[w, 2]] = v[w] /. solution; w++];
    For[w = 1, w < (time), mkw[[w, 1]] = w; w++];

    mkw[[All, 2]] = Flatten[mkw[[All, 2]]];

    Export["ie2.txt", mkw, "Table"];
    Import["ie2.txt", "Table"]

    Out[17]= {{1, "v[1]"}, {2, "v[2]"}, {3, "v[3]"}, {4, "v[4]"}, {5,
      "v[5]"}, {6, "v[6]"}, {7, "v[7]"}, {8, "v[8]"}, {9, "v[9]"}}


Regards,
-- Jean-Marc


  • Prev by Date: Re: Can't Simplify logical expression
  • Next by Date: Re: Function Programming Problems
  • Previous by thread: Re: Writing to an External file, ie .txt
  • Next by thread: RE: Re: (genetic algorithms) Re: How to find the Max of a Piecewise function