MathGroup Archive 2010

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

Search the Archive

Re: exporting an array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113788] Re: exporting an array
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sat, 13 Nov 2010 00:57:45 -0500 (EST)
  • References: <ibgitf$e7p$1@smc.vnet.net>

On 11/11/10 11:09, nt wrote:
> Hi,
>
> I have a question on how to export a matrix. My code generates a
> vector of dimension (200 X 1), and I define:
>
> b = Table[b1[i] /. solution, {i, 1, 200}];
>
> I want to assign counters to these values, and have 1,2,3,.....,200 as
> the first column. Finally I want to export this (200 X 2) matrix to a
> file. I tried the following but they don't work:
>
> Export["file.txt", {i, 1, 2000}, b];
> Export["file.txt", i, b];
>
> I would appreciate it if anyone could suggest a way to do this.
>
> Thanks
> nt
>
>
>
>
>
It always helps to look up the help for a function that you wish to use 
- this would avoid wasting time on syntax like:

Export["file.txt", {i, 1, 2000}, b]

(Click on Export, and press F1)

Here is some code that takes the matrix 'b' and makes into a matrix with 
the indices, and then transposes the result, so you get a column of 
indices and a column of numbers.

The export is to a comma separated file (CSV) - this will be easy to 
re-import into Mathematica using Import.

In[3]:= Export["~/test/hope.csv", Transpose[{Range[1, 200], b}]]

Out[3]= "~/test/hope.csv"

David Bailey

http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Constructing matrix out of submatrices
  • Next by Date: Sort a List, in a List of Lists of Lists
  • Previous by thread: Re: exporting an array
  • Next by thread: Re: exporting an array