[Date Index]
[Thread Index]
[Author Index]
Re: Need help with Mathematica
*To*: mathgroup at smc.vnet.net
*Subject*: [mg115918] Re: Need help with Mathematica
*From*: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
*Date*: Tue, 25 Jan 2011 06:34:14 -0500 (EST)
*References*: <ihm4me$kfs$1@smc.vnet.net>
Hi Martin,
Assuming your problem lies in generating the filenames and not in
actually pushing some output to these files (which can be done in
various ways, among which Export, Put, Save, Write; you can look them
up in the documentation), filename strings can be generated in a loop
like
Do[Print["X" <> ToString[i]], {i, 1, 10}],
where <> is the string concatination operator and ToString converts
expressions to strings. Instead of ToString you could also use
IntegerString which allows you to choose the number of positions your
number should take, padding with leading zeros where necessary (nice
if you want the filenumbers in the correct order in a sort). Instead
of Printing the strings, as I do here, you should do something useful
with the string, ofcourse.
As to Do loops: it is a construction many of this newsgroup's
inhabitants frown upon. Mathematica has a whole array of so-called
functional programming constructs that are considerable more succinct
and efficient. You might want to look at a reference section such as
guide/FunctionalProgramming, especially the functions Map and Apply.
Cheers -- Sjoerd
On Jan 25, 10:21=C2 am, Martin Vavpoti=C4=8D <martin.vavpo... 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 Mathemat=
ica.
> 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: Recursive function**
Next by Date:
**Re: Mathematica 20x slower than Java at arithmetic/special functions, is**
Previous by thread:
**Re: Need help with Mathematica**
Next by thread:
**Re: Need help with Mathematica**
| |