MathGroup Archive 2004

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

Search the Archive

Re: How to read a string from a file?

  • To: mathgroup at
  • Subject: [mg46950] Re: How to read a string from a file?
  • From: Bill Rowe <readnewsciv at>
  • Date: Wed, 17 Mar 2004 02:29:05 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 3/16/04 at 2:37 AM, yupeng_ at (Peng Yu) wrote:

>I have a file called outpara.txt. The content is
>k_9=1,DELTA_T=0.1,DURATION=5000000, SAMPLE_PERIOD=50000"

>I want Mathematica read the content of the file into a string. And
>then display this string as the caption of a graph generated by

You didn't show what you had tried so it is not obvious what the difficulty is. Nor is it obvious what you mean by "caption".

Reading the contents of the file can easily be done using str=ReadList["outpara.txt",String]

With a shorter string, ListPlot has several options that might be suitable. For example there is

ListPlot[data, ... PlotLabel->str] or

ListPlot[data, ... Epilog->{Text[str, {xloc,yloc}]}]

The problem with both of these options is the length of the string you've indicated above is longer than the width of the plot you are likely to create. Neither of these solutions will break a long string automatically.

You could try looking at the position of each comma, then replacing appropriate commas with a newline character. That would result in a multiple line output when using PlotLabel or Epilog.

Another approach might be to have the string and plot in separate cells.
To reply via email subtract one hundred and four

  • Prev by Date: doing things on a procedural way and doing them on a functional way
  • Next by Date: Re: Exact real solutions of cubic equations
  • Previous by thread: Re: How to read a string from a file?
  • Next by thread: q's about NumericQ and saving interpolating function