MathGroup Archive 2010

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

Search the Archive

Re: exporting numerical data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106686] Re: exporting numerical data
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 21 Jan 2010 04:51:58 -0500 (EST)
  • References: <hj6qea$8q2$1@smc.vnet.net>

Am 20.01.2010 12:46, schrieb:
> Hi,
> 
> I have the following problem:
> I've created a table in mathematica that looks like this:
> TabIntegral={ {{m_1,k_1,F(m_1,k_1)},{m_1,k_2,F(m_1,k_2)},...
> {m_1,k_N,...,F(m_1,k_N)}} , {{m_2,k_1,F(m_2,k_1)},{m_2,k_2,F
> (m_2,k_2)},...,{m_2,k_N,F(m_2,k_N)}} , ... , {{m_N,k_1,F(m_N,k_1)},
> {m_N,k_2,F(m_N,k_2)},...,{m_N,k_N,F(m_N,k_N)}} };
> So something like an array of {x,y,F(x,y)} records. Now, I'd like to
> save this in human readable form in a file in such a way that I'd have
> three columns:
> m_1   k_1  F(m_1,k_1)
> m_1   k_2  F(m_1,k_2)
> ...
> m_1   k_N  F(m_1,k_N)
> m_2   k_1  F(m_2,k_1)
> ...
> m_2   k_N  F(m_2,k_N)
> ...
> m_N   k_N  F(m_N,k_N)
> 
> I've tried like that:
> Export["TabIntegral.dat", TabIntegral, "Table"]
> but I got smth like this:
> {0, 0, 5.641587818867172*^-9}   {0, 0.2271979480396873,
> 5.6073615530027356*^-9} {0, 0.4543958960793746,
> 5.503771348500282*^-9}...
> which is definitely not what I need. So now I guess my question is
> clear, how can I get what I need?

you need to get rid of one level of lists, Flatten will help to do that,
like so:

data = Table[{x, y, Exp[-20*x*y]}, {x, 0., Pi, Pi/5.}, {y, 0., Pi,
   Pi/5.}]

Export[FileNameJoin[{$HomeDirectory, "Desktop", "tst.dat"}],
 Flatten[data, 1], "Table"]

> The second question would be the following: as you see I have in my
> file small numbers such like 5.6073615530027356*^-9 that I'd like to
> read later on with a C-written program. If I'll leave it in this
> format as it is, there's no way C-program can read that. So how to
> write/format such small numbers while exporting to guarantee that I'll
> be able to C-read them later?

that is slightly more complicated, you could try something like this,
but there might be other and better possibilities:

Export[
 FileNameJoin[{$HomeDirectory, "Desktop", "tst.dat"}],
 StringJoin[
  Riffle[Map[
    Function[row, Riffle[ToString[CForm[#]] & /@ row, "\t"]],
    Flatten[data, 1]], "\n"]],
 "Text"
 ]

hth,

albert


  • Prev by Date: Re: StringCases matching on portions of sublist?
  • Next by Date: looping
  • Previous by thread: Re: exporting numerical data
  • Next by thread: Re: exporting numerical data