Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4690] can an "array" start with an index other than 1?
  • From: steve at gandalf.radonc.washington.edu (Steve Sutlief)
  • Date: Sun, 25 Aug 1996 18:23:16 -0400
  • Organization: University of Washington
  • Sender: owner-wri-mathgroup at wolfram.com

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?

I looked at the command $PreRead (and $Pre), but I could only think
of a way to use this for one dimensional arrays. For an array "b":

$PreRead = StringReplace[#, {"b[[" -> "b[[6+"}] &

The two kludges I could use in C won't work in Mathematica:

#include <stdio.h>

#define b(x) a[x+5]

main ()
{
  int a[11] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
  int i, *c = a+5;

  for (i = -5; i < 6; i++)
    printf("a[%2d] = %d, b(%2d) = %d, c[%2d] = %d\n",
            i+5, a[i+5],     i, b(i),     i, c[i]);

  return 0;
}

Steve Sutlief
steve at radonc.washington.edu
--
Steve Sutlief, Ph.D.            project: dynamic conformal radiation therapy
Radiation Oncology Dept.        email:   steve at radonc.washington.edu
University of Washington        office:  (206) 548-6671
Box 356043                      fax:     (206) 548-6218
Seattle, Washington 98195-6043  web:     http://weber.u.washington/~sutlief

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: How to think about Map[ ] ?
  • Next by Date: Re: --->What is the problem with 'ParametricPlot
  • Previous by thread: can an "array" start with an index other than 1?
  • Next by thread: Re: can an "array" start with an index other than 1?