|
[Date Index]
[Thread Index]
[Author Index]
Re: can an "array" start with an index other than 1?
- To: mathgroup at smc.vnet.net
- Subject: [mg4728] Re: can an "array" start with an index other than 1?
- From: wagner at motel6.cs.colorado.edu (Dave Wagner)
- Date: Sat, 31 Aug 1996 03:57:45 -0400
- Organization: University of Colorado, Boulder
- Sender: owner-wri-mathgroup at wolfram.com
In article <4vqihp$qrn at dragonfly.wolfram.com>,
Steve Sutlief <steve at gandalf.radonc.washington.edu> 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
>Mathematica?
>
>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 princon.com
http://www.princon.com/princon
==== [MESSAGE SEPARATOR] ====
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
|