Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: FileNamesin a loop..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62096] Re: FileNamesin a loop..
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 11 Nov 2005 02:52:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 11/10/05 at 2:50 AM, uli.wuerfel at fmf.uni-freiburg.de (Uli Würfel)
wrote:

>I want to carry out the same calculation repeatedly, but with
>different sets of parameters. The parameters are located in files
>and I tried to use

>dateien = FileNames["para*.txt"]

>Then, I wanted to use a simple loop in the way:

>For[i=1,i<=Length[dateien],
>{
>  str=OpenRead[dateien[[i]]];
>  ---- Reading of parameters ---
>  Close[str];
>  -----calculations---
>};
>i++]

>Unfortunately, it does not work. Could you help?

What you have outlined above should work. The fact that it doesn't work indicates the problem is with the parts of the code you didn't post. So without additional detail, it is impossible to identify the issue. However, it might be worth pointing out the For loop isn't needed. Instead you could structure things as follows:

parameterReadFunction[filename_String]:= ...
caluculationFunction[parameters...]:= ...

calculationFuction[paramterReadFunction@#]&/@FileNames["para*.txt"]

One of the advantages of structuring the code this way is it makes it easier to debug.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: ((a&&b)||c)==((a||c)&&(b||c)) is not true
  • Next by Date: Re: FileNames[] in a loop..
  • Previous by thread: Re: Integrate problem?
  • Next by thread: Re: FileNamesin a loop..