Re: exporting an array
- To: mathgroup at smc.vnet.net
- Subject: [mg113801] Re: exporting an array
- From: Raffy <adraffy at gmail.com>
- Date: Sun, 14 Nov 2010 06:06:13 -0500 (EST)
- References: <ibgitf$e7p$1@smc.vnet.net>
On Nov 11, 3:09 am, nt <sagittarius5... at gmail.com> 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 You could just build the desired table when your extracting the vector: Export["file.txt", Table[{i, b1[i] /. solution}, {i, 200}]]; Or, you could take your b vector and pair it with an index: Export["file.txt", Transpose@{Range@Length[b], b}]; Or, you could take the procedural approach: Export["file.txt", Table[{i, b[[i]]}, {i, Length[b]}]];