indices

index_as_expression

 An index can be any expression that results in a scalar or a vector. The
 index expression is evaluated first, and the resultant values are truncated
 to integers. For example, suppose x = [1;2;3;...;100], then:

 =x[1:10:2]        ! displays   1  3  5  7  9
 =x[2.1;2.5;2.9]   ! displays   2  2  2
 y=[2:5]           !   define Y to be   2  3  4  5
 =x[y/2+3]         ! displays   4  4  5  5
 z=[2;3]           !   define Z to be   2  3
 =x[y[z+1]-2]      ! displays   2  3

special_characters

 There are two special characters that are defined only within a variable
 index: # denotes the last element of a dimension, and * denotes the
 entire range of a dimension. The * character is not allowed on string
 variables. The # character can be used in an index expression, for example,
 X[#-1] is the next to last element of vector X.

 # and * cannot be used in indices on output variables, since they
 would be undefined. They also cannot be used in indices on functions
 or in indices on expressions.

Additional Information on:

  • examples
  • functions

     Indices can be used on any function, except for the array functions
     LOOP, SUM, PROD, RSUM, and RPROD. For example, if x and y are vectors
     of length 10, then sin(x+y) is also a vector of length 10, and an index
     can be used, such as sin(x+y)[3].  The special index characters # and *
     cannot be used in indices on functions.
    

    expressions

     Indices can be used on an expression. For example, if x and y are
     vectors of length 10, then (x+y) is also a vector of length 10, and
     an index can be used, such as (x+y)[3].  The special index
     characters # and * cannot be used in indices on expressions.
    

    starting_value

     By default, a variable index starts at one (1), but you can define
     variable indices to start at any integer value, positive or negative.
     For example:
    
     x = [1:100]       ! define a vector X to be the numbers 1;2;3;...;100
     x[-5:3]=x[1:9]    ! redefine X to have a starting index of -5
     y=[1:106]         ! make vector Y with same length as X, starting at 1
     z=x+y             
     SHOW\VECTORS      ! display information on all vectors
     ---------------------------------------------------------------------
     vector indices     length history
     ---------------------------------------------------------------------
          X [ -5:100 ]     106 X[-5:3]=[1:9]
          Y [ 1:106 ]      106 Y=[1:106]
          Z [ 1:106 ]      106 Z=X+Y
    
     The FIRST function returns a scalar value equal to the starting index of
     a vector, while the LAST function returns the final index of a vector.
     The LEN function returns a scalar value equal to the total length of a
     vector.  The VLEN function returns a vector whose n'th element is the
     length of the n'th dimension of its argument. VLEN of a vector returns
     a vector of length 1, while VLEN of a matrix returns a vector of length 2.
    
     The CLEN function returns a scalar value equal to the length of a string.
     The TLEN command gives the number of string elements in a string array.