Re: How to read a data file in text format?_from a new learner

*To*: mathgroup at smc.vnet.net*Subject*: [mg62359] Re: How to read a data file in text format?_from a new learner*From*: "jeff langston" <mightyspeck at hotmail.com>*Date*: Tue, 22 Nov 2005 04:42:00 -0500 (EST)*References*: <dls56u$nue$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hello! try something like this: transData = Rest[ Import["(directory file is in)/data.txt", "CSV"] ]; If for example your file is in the folder C:\experimental data, don't use "C:\experimental data\data.txt" Instead, use the following in the import command: "C:/experimental data/data.txt" The reason is that sometimes you can have directories/files starting with an r or t or some other character where mathematica, for arguments in quotes, interprets it differently than you would think, e.g., /t means tab, where \t means just characters in a string. It doesn't matter if the t or r was buried, e.g., C:\Documents\trig stuff The function Rest in front gets rid of the first line in your data. transData will then look like the following: {{200, 45.5},{201,44.3},...,{1,0,76.3}} Which brings up a question.... I am assuming that the indices are in numerical order. Are indicies greater than 1000 written with a comma in them? (1,000) If so, you can tack on the following: transData = Map[ If [ Length[#] > 2, {1000 #[[1]] + #[[2]] , #[[3]] }, # ] &, transData]; which would make transData look like the following: {{200, 45.5},{201,44.3},...,{1000,76.3}} Basically, this fcn checks every list in transData and makes sure that its length is less than 2. If it is not, 1000 is multiplied by the first element in the sublist #[[1]] and added to the second element in the sublist #[[2]], therefore combining them. The previously third element #[[3]] becomes the second. If the length is less than 2, the sublist stays the same. As far as graphing them, you could use: ListPlot[transData] Hope this has helped... jeff langston "deepthinker" <yanshanguke at 163.com> wrote in message news:dls56u$nue$1 at smc.vnet.net... > I want to import a data file that produced by spectrometer into > mathemathica and fit the data. The file is in text format ("data.txt"). > The data in the file is characters: first line:some descriptions. > second line: 200, 45.5. third line: 201,44.3. and so on. If you open > the file "data.txt", you will see: > transmission ratio by UV-3150 > 200, 45.5 > 201,44.3 > 202,44.6 > 203,46.7 > ... > 1,000,75.5 > 1,000,76.3 > > How to import these data in to mathematica 5.0 and plot the figure? > Thank you very much >

**Follow-Ups**:**Re: Re: How to read a data file in text format?_from a new learner***From:*gardyloo <gardyloo@mail.wsu.edu>