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 1996

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

Search the Archive

Re: can an "array" start with an index other than 1?

  • To: mathgroup at
  • Subject: [mg4728] Re: can an "array" start with an index other than 1?
  • From: wagner at (Dave Wagner)
  • Date: Sat, 31 Aug 1996 03:57:45 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at

In article <4vqihp$qrn at>,
Steve Sutlief <steve at> wrote:
>I would like to have a multidimensional array with an index running 
>from -5 to 5, for example.  Is there a kludge for doing this in 
>The two kludges I could use in C won't work in Mathematica:
>#define b(x) a[x+5]

No?  Why not define

	b[x_] := a[[x+6]]

and use b[-5] to refer to a[[1]], analogous to what you did in your
C program?

In fact, Mathematica can even make it look like b is being indexed,
not called as a function (try getting this to work in C!), by doing this:

	b /: b[[x_]] := a[[x+6]]

Now you can use b[[-5]], rather than b[-5], to refer to a[[1]].
But the first way might even be prefereable to you, since it looks
more like C and you're obviously a C programmer at heart.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at


  • Prev by Date: Mathematica Crashing - Floating Point problem?
  • Next by Date: Where'd Mathematica World go?
  • Previous by thread: Re: can an "array" start with an index other than 1?
  • Next by thread: Help: FrameLabel Option