MathGroup Archive 2003

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

Search the Archive

Re: Q: (how?) notebooks with I/O loop

Jason Miller <millerj at> wrote in message news:<b5rme7$eum$1 at>...
> Dear Mathematica Gurus.
> I am working with a student (undergraduate math major) who is using 
> Wavelet Explorer to process numerous datasets using a multiresolution 
> analysis with various parameter settings.  We would like to know how 
> we might create a notebook that would
> 	(1) read in a datafile from a list of files in a local 
> directory (or in a hardcoded array),

Ok Jason. First of all you need to create a list of the files in your
local directory. If you work with Linux/Unix you can do that writing
"ls >> inputfiles.txt" in the shell. If you work with Windows, you can
use Cygwin, A Unix enviroment under Windows.

Now well, to avoid writing the complete route of the files you have to

SetDirectory["D:\\local directory"]

"D:\\local directory"

Then you have to transform the list into a Mathematica list 

inputfiles = ReadList["inputfiles.txt", Record]

{"a1.txt", "a2.txt", "a3.txt", "inputfiles.txt"}

In every ai.txt I wrote arrays of numbers of order 3 x 3. In order to
read and use them as matrices I use

data = ReadList[#, Number, RecordLists -> True] & /@ Drop[inputfiles,

{{{1, 3, 5}, {4, 6, 8}, {5, 7, 9}}, {{2, 3, 9}, {1, 4, 2}, {5, 8, 4}},
{{7, 3, 6}, {9, 4, 1}, {5, 0, 3}}}

> 	(2) run a multiresolution analysis on the file (this analysis 
> is already coded)
> 	(3) save the results (e.g., in the form of a mathematica notebook),

Suppose that you want to calculate the determinants of data and save
the results in  a notebook with the same name of input file. First you
make the calculations

results = Det[#] & /@ data

{0, -90, -102}

After that you have to make a list of outputfiles

outputfiles = Drop[StringReplace[#, "txt" -> "nb"] & /@ inputfiles,

{"a1.nb", "a2.nb", "a3.nb"}

And finally you have to put the results in the outputfiles

Table[Put[results[[i]], outputfiles[[i]]], {i, Length[results]}]

{Null, Null, Null}

> 	(4) do the same in turn for each of the datasets in a local 
> directory, as described in (1).
> Having a way to create such a 'loop' would save us much time, but 
> we're don't know how to direct Mathematica to save the results of 
> each analysis.

The function that makes all this for you is

readingandsaving[listoffiles_String] := 
  Module[{inputfiles = ReadList[listoffiles, Record]},
    data = 
      ReadList[#, Number, RecordLists -> True] & /@ Drop[inputfiles,
    outputfiles = Drop[StringReplace[#, "txt" -> "nb"] & /@
inputfiles, -1];
    results = Det[#] & /@ data;
    Table[Put[results[[i]], outputfiles[[i]]], {i, Length[results]}]]

> Can anybody tell us how we might do this, or if it's a reasonable thing to do?
> Thank you in advance.
> Jason

Hope this help


  • Prev by Date: Re: help buttons
  • Next by Date: Re: Questions concerning printing,editing, and copy/paste
  • Previous by thread: Re: Q: (how?) notebooks with I/O loop
  • Next by thread: cryptografy & mathematica