RE:data files
- To: mathgroup at smc.vnet.net
- Subject: [mg31191] RE:[mg31164] data files
- From: "Helge Andersson" <helgea at inoc.chalmers.se>
- Date: Wed, 17 Oct 2001 05:35:13 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Tim wrote: 2001-10-14 10:12
I wish to plot data stored as a matrix in a text file. I also want to
be able to output data into a file. How can I achieve this ?
Thanks
Tim
__________________
Hello Tim,
Here are functions that you can use for reading and storing
2-dimensional data.
ListToSpreadsheet[path_String,data_List]:=Module[
{strm=OpenWrite[path],len=Length[data]},
WriteString[strm,
StringReplace[
ToString[
FortranForm/@data[[#]]],{","->"\t","{"->"","}"->""}]<>"\n"]&/@Range[len]
;
Close[strm]
]
SpreadsheetToList[path_String]:=ReadList[path,Number,RecordLists->True];
If you want to delete the headers from the original spreadsheet you can
delete the first line like this:
SpreadsheetToList2[path_String]:=Delete[ReadList[path,Word,RecordLists->
True,RecordSeparators->{"\n"}],1];
/Helge
Fil Dr. Helge Andersson
Oorganisk miljökemi
CHALMERS
SE-412 96 Göteborg