MathGroup Archive 2002

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

Search the Archive

Re: Mathematica function writing for data analysis at Gould Academy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35742] Re: Mathematica function writing for data analysis at Gould Academy
  • From: Peter <petsie at arcor.de>
  • Date: Sun, 28 Jul 2002 03:32:24 -0400 (EDT)
  • References: <ahr0u6$l2l$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Charles H. Dresser wrote:
 > Hello,
 > I work at Gould Academy and have recently taught myself some of the
 > Mathematica scripting language. It has been my job to write functions
 > which will make analyzing data in Mathematica simpler for the
 > students. I have written a number of scripts which find different
 > regressions of data within a file easily. But, a couple of the
 > functions that I have written are not doing exactly what I want them
 > to do. One of them takes the input from a file with multiple columns
 > and what number columns the user wants to be included in the data as
 > ordered pairs and is suppose to output the ordered pairs which was
 > selected. What it does is it doesn't output anything but does set list
 > equal to the data which it should output.  This is the code I have
 > written (Sorry If It Is Ugly):
 >
 > f is a filename x is the column which is wanted to be the x value in
 > the order pairs y is the y value which is wanted to be the ordered
 > pairs.
 >
 >   MultCol[f_, x_, y_] :=
 >   Do[For[i = 1; list = {}; length = Length[Import[f, "Table"]], i <=
 > length,
 >         i++,
 >         list =
 >           Append[list, {Part[Part[Import[f, "Table"], i], x],
 >               Part[Part[Import[f, "Table"], i], y]}]]
 > MultColCleanUp[], {1}]
 >
 > MultColCleanUp[] :=
 >   If[DigitQ[StringTake[ToString[First[list]], {2}]], list = list,
 >     list = Rest[list]]
 >(...)

MultCol[f_,x_,y_]:=
     Select[ Import[f, "Table"][[All, {x, y}]], NumberQ[First[#]]& ]
should work.

   If you want to keep your Functions, you should consider using local variables:
MultCol[f_,x_,y_]:=Module[{list,i}, Do[...]; list]
but in my opinion it is bad style (sorry), to read the file 2*length times.
   To assign the result to the global variable list do:
list = MultCol[f,2,5].

Regards,
Peter
-- 
u will c how to mail me...



  • Prev by Date: Work with Contexts
  • Next by Date: Re: how to solve for periodic solution?
  • Previous by thread: Re: Mathematica function writing for data analysis at Gould Academy
  • Next by thread: Re: Mathematica function writing for data analysis at Gould Academy