MathGroup Archive 2000

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

Search the Archive

Re: Manipulating List Elements In Programs


Buz,

The trouble may be in the use of Delete

1) Delete[z,{1,2}] needs to be Delete[z,{{1},{2}]
2) Delete[z,{{1},{2}] does not alter the value of z, it simplygives as
output the value of z with the first two elements deleted.

The following might work

files = FileNames["output*.dat"];
l = Length[files];

For[i = 1, i <= l, i++,
z = Import[ files[[i]]];
title = z[[1]];
lab = z[[2]];
lst = Delete[z, {{1}, {2}}];
ListPlot[lst, AxesLabel -> lab, PlotLabel -> title] ]


A more functional form is

ListPlot[Drop[#, 2],
          PlotLabel -> #[[1]],
          AxesLabel -> #[[2]]] &[Import[#]
] &/@ FileNames["output*.dat"]

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Buz Barstow" <buz at sys-j25.demon.co.uk> wrote in message
news:8icdhn$9sk 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
>
>




  • Prev by Date: Re: Syntax error using (*comments*)
  • Next by Date: RE: Fast (compiled) routine for element testing and replacement in large matrices?
  • Previous by thread: Re: Manipulating List Elements In Programs
  • Next by thread: Re: how to get automatic correction?