MathGroup Archive 2003

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

Search the Archive

Re: Simple List question. HELP.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39430] Re: Simple List question. HELP.
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Fri, 14 Feb 2003 03:25:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 2/13/03 at 4:55 AM, dhenegha at bway.net (Daniel Heneghan) wrote:

>I am new to Mathematica. This is vexing. All I want to do is create a
>2-dimensional list so that I can enter x,y values and then plot the
>list. I want to do this programmatically. I am having such incredible
>trouble trying to accomplish this simple task. I know that there is
>probably a Mathematica optimized way to do this, but I and trying to
>write a little program and for now I want to stay with paradigms that
>I am familiar with. Here is what I have been doing.

>Create a 2 dimensional list. 
>In[532]     lst={{}}
>Out[532]=    {{}}

This creates a list having as the first element an empty list. Better would be to just create an empty list as in

In[5]:=lst = {}
Out[5]={}

>Enter the first pair into the first place in the list. 
>In[533]:=lst[1]={{0,1}}

In order to work as you want the syntax needs to be change to be
lst[[1]] = {0,1}

In Mathematica lst[1] is interpreted as a function named lst with arguement 1. lst[[1]] refers to the first element of a list named lst. Note, you want the first element of this list to be the pair of numbers 0 and 1. So, it is entered as {0,1} not {{0,1}}

If you were to take my suggestion above, the first element would be added with Append[lst,{0,1}].

>Add anoter pair of values.

>In[534]:= lst=Append[lst,{{1,2}}] 
>Out[534]= {{},{{1,2}}} 

Again, you have an additional level you will not want later. Adding the second item would be done by

Append[lst,{1,2}]. Note, this is the same syntax as would be needed for adding the first item if you take my suggestion to start with lst = {}.

>The reason I need to do this is that for the list plot I need the x values to start at 0 not 1.

The suggestions I gave here will work and are in keeping with your request to not use Mathematica paradigms. But they are very inefficient for solving the problem you indicated here.

If you have a list of  n numbers to be plotted against the integers 0,1 ... n-1, then all you need do is

ListPlot[Transpose[{Range[0,Length[lst]-1],lst}]];

or even better

ListPlot[lst, Ticks->{Table[{k,,k-1},{k,Length[lst]}],Automatic}]


  • Prev by Date: Re: Simple List question. HELP.
  • Next by Date: Re: Simple List question. HELP.
  • Previous by thread: Re: Simple List question. HELP.
  • Next by thread: Re: Simple List question. HELP.