Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Manipulating List Elements In Programs

  • To: mathgroup at
  • Subject: [mg23972] Re: [mg23940] Manipulating List Elements In Programs
  • From: BobHanlon at
  • Date: Sun, 18 Jun 2000 03:00:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

In a message dated 6/16/2000 1:26:13 AM, buz at writes:

>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
>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
>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?
test = Range[5]; 

The correct form of Delete to remove the first two elements is

Delete[test, {{1}, {2}}]

{3, 4, 5}

However, this does not change the contents of test


{1, 2, 3, 4, 5}

If you want the contents of test to change:

test = Delete[test, {{1}, {2}}]

{3, 4, 5}


{3, 4, 5}

You might want to consider using Drop

test = Range[5]; 

test = Drop[test, 2]

{3, 4, 5}

Bob Hanlon

  • Prev by Date: AW: Re: Integrate returns 0
  • Next by Date: Re: Manipulating List Elements In Programs
  • Previous by thread: Manipulating List Elements In Programs
  • Next by thread: Re: Manipulating List Elements In Programs