Re: outputting lists
- To: mathgroup at smc.vnet.net
- Subject: [mg9870] Re: [mg9836] outputting lists
- From: David Withoff <withoff>
- Date: Sat, 29 Nov 1997 00:10:59 -0500
- Sender: owner-wri-mathgroup at wolfram.com
> I have a simple problem,
>
> Suppose I have a mathematica list that represents a number of
> n-dimensional vectors. e.g. {{2,3},{3,2},{6,5},{7,7},{1,1}}
> which represents five 2d vectors.
>
> Does anyone know an easy way of outputting this list to a file so that
> each line contains just a single n-dim vector with elements seperated
> by either spaces or commas.
> e.g. for the above example the file should be:
>
> 2 3
> 3 2
> 6 5
> 7 7
> 1 1
>
> Or
>
> 2,3
> 3,2
> 6,5
> 7,7
> 1,1
>
> thanks,
>
> Zahir
If you can get what you want on the computer screen, then you can write
it to a file. For example:
In[7]:= data = {{2,3},{3,2},{6,5},{7,7},{1,1}} ;
In[8]:= result = TableForm[data, TableSpacing -> {0,1}]
Out[8]//TableForm= 2 3
3 2
6 5
7 7
1 1
In[9]:= Write["file", OutputForm[result]]
In[10]:= Close["file"] ;
In[11]:= !!file
2 3
3 2
6 5
7 7
1 1
Writing out comma-separated data is slightly more complicated. Here is
one way to do it:
In[11]:= Scan[Write["file", OutputForm[Infix[#, ","]]] &, data]
In[12]:= Close["file"] ;
In[13]:= !!file
2,3
3,2
6,5
7,7
1,1
Dave Withoff
Wolfram Research