1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<HTML>
<HEAD>
<TITLE>Indices</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<P><A NAME="indices"></A>
<font size="+3" color="green">Indices</font></P>
<P>
Indices can be used on any numeric variable, except scalars, and on any string
variable. A string variable is a string, and can have only one index, which
is interpreted as a character index. A string array variable is an array of
strings, and can have either one or two indices. If one index is used, it is
assumed to be an array index. If two sets of indices are used, the first is
assumed to an array index and the second is assumed to be a character index.
Indices can also be used on functions and on expressions. An index can be a
simple numeric literal or a complicated expression. Indices can also be
nested.</P>
<P>
An index is enclosed in square parentheses, <CODE>[</CODE> and <CODE>]</CODE>.
Actually, <CODE>()</CODE> and <CODE>{}</CODE> work as well, but <CODE>[]</CODE>
are used in the documentation to alleviate confusion. The colon, <CODE>:</CODE>, is the range
separator while the semicolon, <CODE>;</CODE>, is the element separator. For example,
<CODE>[1:5]</CODE> represents the set of numbers <CODE>[1;2;3;4;5]</CODE>.
An increment is optional with a range, and defaults to one <CODE>(1)</CODE>.
For example, <CODE>[1:5:2]</CODE> represents the set of numbers <CODE>[1;3;5]</CODE>.</P>
</P>
<P>
There are two special characters that are defined only within a variable
index: <CODE>#</CODE> denotes the last element
of a dimension, and <CODE>*</CODE> denotes the
entire range of a dimension. The <CODE>*</CODE> character is not allowed on string variables. The
<CODE>#</CODE> character can be used in an
index expression, for example, <code>X[#-1]</code>
is the next to last element of vector <code>X</code>. Refer to the table
below for some examples of these special index characters.</P>
<p>
<center>
<table border="1" cellpadding="10">
<tr>
<td><code>X[#]</code></td>
<td>is the last element of vector <code>X</code></td>
</tr><tr>
<td><code>TS[#]</code></td>
<td>is the last character of string variable <code>TS</code></td>
</tr><tr>
<td><code>TA[#]</code></td>
<td>is the last string of string array variable <code>TA</code></td>
</tr><tr>
<td><code>TA[#][3:7]</code></td>
<td>is characters <CODE>3</CODE> to <CODE>7</CODE> of the last string of <code>TA</code></td>
</tr><tr>
<td><code>M[#,2:10]</code></td>
<td>is elements <CODE>2</CODE> to <CODE>10</CODE> from the last row of matrix <code>M</code></td>
</tr><tr>
<td><code>M[3:12,#-1]</code></td>
<td>is elements <CODE>3</CODE> to <CODE>12</CODE> from the next to last column of <code>M</code></td>
</tr><tr>
</tr><tr>
<td><code>X[*]</code></td>
<td>is all of vector <code>X</code></td>
</tr><tr>
<td><code>M[3,*]</code></td>
<td>is all of row <CODE>3</CODE> from matrix <code>M</code></td>
</tr><tr>
<td><code>M[*,5]</code></td>
<td>is all of column <CODE>5</CODE> from <code>M</code></td>
</tr>
</table></center></p>
<P>
<CODE>#</CODE> and <CODE>*</CODE> 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.</P>
<P>
<a href="IndicesS01.htm"><font size="+1" color="olive">Indices on functions</font></a><br />
<a href="IndicesS02.htm"><font size="+1" color="olive">Indices on expressions</font></a><br />
<a href="IndicesS03.htm"><font size="+1" color="olive">Index as expression</font></a>
</P>
<P>
<a href="Variables.htm"><img src="../shadow_left.gif">
<font size="+1" color="olive">Variables</font></a><br />
<a href="Expression.htm"><img src="../shadow_right.gif">
<font size="+1" color="olive">Expressions</font></a>
</P>
</body>
</html>
|