MathGroup Archive 2011

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

Search the Archive

Re: Need help with Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115909] Re: Need help with Mathematica
  • From: Gabriel Landi <gtlandi at gmail.com>
  • Date: Tue, 25 Jan 2011 06:30:17 -0500 (EST)

Here is how I would do it. I prefer the Do function instead of the For but
both would work.

Do[
       Import["P" <> ToString[i] <> ".txt", "Table"];
       Perform your calculations. Generate Q_DATA, R_DATA, S_DATA;
       Export["Q <> ToString[i] <> ".txt", Q_DATA];
       Export["R <> ToString[i] <> ".txt", R_DATA];
       Export["S <> ToString[i] <> ".txt", S_DATA],
    {i, 1, N}
]

The "<>" guy joins strings and since i is a number, ToString[i] needs to be
used to convert it to a string.

You can also use FileNames[] function to get the files you want.
First use SetDirectory["C:\\blablabla\blablabla"] and then FileNames will
list all files in that directory.

Hope it helps,

Gabriel

On Tue, Jan 25, 2011 at 7:21 AM, Martin Vavpoti=C4=8D
<martin.vavpotic at gmail.com>wrote:

> Hello to everyone.
>
> I am in dire need of some assistance with Mathematica. First of all, I
> need to know how to write a for loop that would create a series of
> output files numbered according to the index of the said loop. For
> instance, I want to feed Mathematica with a series of input files
> named P1.txt, P2.txt, etc. The equation I'm working on outputs three
> files: Q1.txt, R1.txt, S1.txt for the first input. I want the loop to
> tell my program how to name my files.
>
> I know how to do this in another system, but I'm rather new with
> Mathematica.
> I've been trying to find a solution for days but apparently the
> difference between both programs is enough for me not to find it.
>
> Any help would be greatly appreciated.
>
>


  • Prev by Date: Re: Fast matrices comparison
  • Next by Date: Re: Recursive function
  • Previous by thread: Re: Need help with Mathematica
  • Next by thread: Re: Need help with Mathematica