MathGroup Archive 2000

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

Search the Archive

RE: Manipulating List Elements In Programs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23959] RE: [mg23940] Manipulating List Elements In Programs
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 18 Jun 2000 03:00:42 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Buz Barstow [mailto:buz at sys-j25.demon.co.uk]
To: mathgroup at smc.vnet.net
> Hi,
>
> I'm trying to write a program in Mathematica to automatically plot graphs
> from text files that I've generated with a C program. It looks in the
> working directory, and retrieves a list of all files with a .dat
> extension;
>
> files = FileNames["output*.dat"]
>
> Then, it gets the number of entries in that list;
>
> l = Length[files]
>
> And then uses this information to import each file individually and do a
> ListPlot with each list;
>
> For[i = 1, i <= l, i++,
>   z = Import[ files[[i]]];
>   title = z[[1]];
>   lab = z[[2]];
>   Delete[z, {1, 2}];
>   ListPlot[z, AxesLabel -> lab, PlotLabel -> title] ]
>
> At the top of each output file there is a heading that I want to
> use as the
> plot's title and two column headings that I want to use to label the axes.
> Unfortunately, I can retrieve them and label the plot, but I can't delete
> them, so when I include the title, I can't produce the plot.
>
> Does Mathematica prevent the programming calls deleting things, or am I
> missing something?
>
> Thanks in advance,
>
> Buz


Buz,

It would be easier to use Drop.

z = {a, b, c, d};

z2 = Drop[z, 2]
{c, d}

Or, if you don't have to preserve the original z:

z = Drop[z, 2]
{c, d}

Then ListPlot z2 or the new z.

Whether you use Drop or Delete, you must do an assignment if you want the
variable to reflect the change.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/






  • Prev by Date: Re: Syntax error using (*comments*)
  • Next by Date: Re: Are notebooks platform dependent ?
  • Previous by thread: Re: Manipulating List Elements In Programs
  • Next by thread: Re: Manipulating List Elements In Programs