File: indexasexpression.htm

package info (click to toggle)
extrema 4.3.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 19,212 kB
  • ctags: 6,452
  • sloc: cpp: 86,428; sh: 8,229; makefile: 814
file content (40 lines) | stat: -rw-r--r-- 1,679 bytes parent folder | download
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
<HTML>
<HEAD>
<TITLE>Indices as expressions</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">

<P><A NAME="indexasexpression"></A>
<font size="+2" color="green">Indices as expressions</font></P>
<P>
 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 <code>x = [1;2;3;...;100]</code>, then:</P>
<P>
 <font color="blue"><PRE>
  =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
 </PRE></font></P>
<P>
 A variable index always starts at one (<CODE>1</CODE>).</P>
<P>
 The <a href="../Functions/VariableCharacteristics/len.htm"><CODE>LEN</CODE></a>
 function returns a scalar value equal to the total length of a vector.  The
 <a href="../Functions/VariableCharacteristics/vlen.htm"><CODE>VLEN</CODE></a>
 function returns a vector whose <i>n</i><sup>th</sup> element is the length
 of the <i>n</i><sup>th</sup> dimension of its argument.
 <CODE>VLEN</CODE> of a vector returns a vector of length <CODE>1</CODE>, while
 <CODE>VLEN</CODE> of a matrix returns a vector of length <CODE>2</CODE>.</P>
<P>
 <EM>Note</EM>:  The <a href="../Functions/VariableCharacteristics/clen.htm"><CODE>CLEN</CODE></a>
 function returns a scalar value equal to the length of a string.</P>
<P>
 <a href="indexonexpression.htm"><img src="../shadow_left.gif">&nbsp;
 <font size="+1" color="olive">Indices on expressions</font></a>
</P>
</body>
</html>