MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Importing (and dealing with) multiple files

  • To: mathgroup at
  • Subject: [mg60801] Re: [mg60778] Importing (and dealing with) multiple files
  • From: <bsyehuda at>
  • Date: Thu, 29 Sep 2005 05:41:11 -0400 (EDT)
  • References: <>
  • Reply-to: bsyehuda at
  • Sender: owner-wri-mathgroup at

You need to Map[] your operations on the list of file names.
I just created a synthetic example (based on the help for NonLinearFit)
I hope it helps
<< Statistics`NonLinearFit`;
CreateDirectory["c:\\datafiles"]; SetDirectory["c:\\datafiles"];
data = {{1.0, 1.0, .126}, {2.0, 1.0, .219}, {1.0, 2.0, .076}, {2.0, 2.0, \
.126}, {.1, .0, .186}};
Do[Export["data" <> ToString[i] <> ".asc", data, "Table"], {i, 5}]

NonlinearFit[Import[#, "Table"], theta1 theta3 x1/(
1 + theta1 x1 + theta2 x2), {x1, x2}, {theta1, theta2,
theta3}] & /@ FileNames[]

On 9/28/05, contact at <contact at> wrote:
> 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

  • Prev by Date: Re: SingularValueDecomposition bug: fifty examples
  • Next by Date: Re: Re: Checking for a given phrase in an expression
  • Previous by thread: Importing (and dealing with) multiple files
  • Next by thread: Re: Importing (and dealing with) multiple files