Re: Importing (and dealing with) multiple files

*To*: mathgroup at smc.vnet.net*Subject*: [mg60829] Re: Importing (and dealing with) multiple files*From*: "John Jowett" <John.Jowett at cern.ch>*Date*: Thu, 29 Sep 2005 05:43:01 -0400 (EDT)*Organization*: CERN - European Laboratory for Particle Physics*References*: <dhdbdh$8f3$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hello, Something like this ? First define a function that returns, say, the filename and the two parameters theta1, theta2 from the results of analysing one data file: stats[fn_] := Module[{rawdata,croppedcorrelation, statistics}, rawdata=Import[fn, "Table"]; croppedcorrelation = Take[rawdata, {75, 185}]; statistics = NonlinearRegress[croppedcorrelation, math_here ...]; {fn, theta1, theta2} /. statistics] Get a list of the files, no need to know how many dataFiles = FileNames["*.ASC", "C:\\"] If each file represents a time point, then the order may matter, in which case you may need to sort them somehow. dataFiles=Sort[dataFiles, someSortingFunction ] Then map the function over the list to return a table. Map[stats, dataFiles] You can adapt the details depending what you want exactly. John Jowett <contact at dantimatter.com> wrote in message news:dhdbdh$8f3$1 at smc.vnet.net... > Hello all, > > I have experimental data that is stored in a number of files. I've > been importing the files (as tables) into Mathematica one-by-one, and > working on them like so: > > rawdata=Import["C:\\filename.ASC", "Table"]; > > croppedcorrelation=Take[rawdata,{75,185}]; > > statistics=NonlinearRegress[croppedcorrelation, math_here...] > > then painstakingly picking out the relevant statistical parameter from > each file, collecting them all, and later plotting them. What I'd > really like to do is import an entire directory's worth of these files > (each file is a different time point), do the same statistical thing to > each file, save the relevant parameters from each file in a table form > and then plot the whole shebang. > > One of the problems is that I don't know ahead of time how many .ASC > files are in the directory, so I need to set up the For loop (or > whatever structure) to account for that. I tried using FileNames[] to > get the list of files, assigning them to an array, then using Import[] > on each of those array elements. It didn't work. > > Does anyone have any suggestions? > > Thanks! > Dan >