MathGroup Archive 2009

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

Search the Archive

Re: Problems in writing into a sequential filename

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97082] Re: Problems in writing into a sequential filename
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Thu, 5 Mar 2009 04:52:04 -0500 (EST)
  • References: <golquh$qab$1@smc.vnet.net>

Hi Xavier,

The problem is you're mixing up various ways of writing to a file in
Mathematica.

With >> and >>> you can write directly to a file without opening it.

OpenWrite give you something like a file handle that is to be used by
functions like Write and WriteString.

All these things are pretty clearly explained in the manual. I'd say:
select '>>>' and press the help button (not sure what it is on a Linux
platform) and you're set.

Relevant tutorials are:
tutorial/ReadingAndWritingMathematicaFiles
tutorial/StreamsAndLowLevelInputAndOutput

(names to be pasted in the help Search bar)

By the way: I don't think it's a good idea to use reals in file names.
For instance, the decimal point may provide your file with an unwanted
extension.

Showing Plots in a loop can be done by adding the Print function.
Indeed, plots can be printed as well As of version 6 this must be done
when plots are used in a loop and there visibility is desired.

Cheers -- Sjoerd

On Mar 4, 2:07 pm, xab... at gmail.com wrote:
> Hi everybody
>
> I am enjoying the beautiful rules of programming in mathematica, and I
> step onto a rock:
> How can I write datas into a sequential filename?
> Let's explain myself, with an exemple below:
>
> First I work on mathematica 6.0.2 on linux
>
> I want to make a Do loop in witch I choose values for a variable: Sr
> (here, 0.5 and 1)
> Then I concatenate a "pattern" and the value (here RappSr and the
> value) and put the name into a variable (Nomfich)
> then I open the file (It works)
> But then, the problem is it does not write into the file, but it close
> it normally.
>
> So How can I do this not-so-tricky-thing in Mathematica?
>
> And by the way, I can't plot graphes into any Loop neither.
>
> Thanks for all your help,
> Cheers
> Xavier
>
> The code:
>
>  ClearAll["Global`*"];
> Do[
> Nomfich = ToString["RappSr" <> ToString[Sr]];
>
>   Print[Nomfich];
>   poiuy4  = OpenWrite[Nomfich];
>
>   Sr >>> Nomfich;
>   1 >>> Nomfich;
>   Close[Nomfich];
>
>   , {Sr, {0.5, 1}}];



  • Prev by Date: Re: Problems in writing into a sequential filename
  • Next by Date: Re: Conjecture: 2n+1= 2^i+p ; 6k-2 or 6k+2 = 3^i+p
  • Previous by thread: Re: Problems in writing into a sequential filename
  • Next by thread: Speed differences between Union, Tally and DeleteDuplicates