ArrayOp1
(Engine-Level Function)
Description: | Performs a mathematical operation on an array with respect to a scalar value. |
Returns: | Nothing |
Usage: | Script only. |
Function Groups: | Array |
Related to: | ArrayOp2 | ArraySize | FFT| Array Functions | WhileLoop | Array Functions |
Format: | ArrayOp1(ArrayElem, N, Scalar, OpCode[, MaskElement]) |
Parameters: |
ArrayElem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Any array element giving the starting point for the array operation. The subscript for the array may be any numeric expression. If processing a multidimensional array, only the right-most subscript is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
N | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Any numeric expression giving the number of array elements to compute. N will be limited to the minimum
of N and the array size. If the starting point given by the first parameter is not the first element, and therefore N extends past the upper bound of the lowest array dimension, this computation will "wrap-around" and resume at the first element. Because N is automatically limited by the smallest array dimension, no element will be processed twice. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Any numeric expression giving the scalar quantity used in the array computation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OpCode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Any numeric expression giving the operation number to perform as follows (note that A is the array element, and S is Scalar):
|
MaskElement |
Optional. The starting element in an array of TRUE and FALSE values, specifying which elements in array, A will be operated upon. The ArrayOp function will only apply to element A[i] if Mask[starting element + i] is a valid TRUE. |
Comments: |
The ArrayOp1 statement is useful for large amounts of repetitive computation. While this can be done by executing a script repeatedly using WhileLoop, this ArrayOp1 statement is much faster. Complex computations may be broken down into a series of simple steps and handled by multiple ArrayOp1 and ArrayOp2 statements. If text arrays are used, each text value will be converted to a number before the numerical operations are performed. The resulting array is converted back to text. Mode 33 will compare for differences. It does a more thorough comparison than a simple A != B. For a multi-dimensional array such as A[X][Y], only the right-most dimension is processed. ([Y] in this example.) You must resort to loops to process the other array dimensions. |
Examples:
If Watch(1); [ SomeArray = New(10) { create an array }; ArrayOp1(SomeArray[0], ArraySize(SomeArray), 0, 0 { Set all elements to zero }); ]
If 1 Main; [ ArrayOp1(pumpTrend[10] { Starting element }, 50 { Number of elements to use }, x + y { Number to use in computation }, 0 { Assign result to the element }); ArrayOp1(sequentNums[0] { Starting element (beginning) }, 10 { Number of elements to use }, 1 { Number to use in computation }, 30 { Assign sequential numbers }); ArrayOp1(evenNums[0] { Starting element (beginning) }, 101 { Number of elements to use }, 2 { Number to use in computation }, 31 { Assign multiples of number }); ]
In this example, the first statement sets elements 10 through 59 of pumpTrend to the result of x + y, the second statement sets elements 0 through 9 of sequentNums to the numbers 1 through 10, and the third statement sets elements 0 through 100 of evenNums to the even numbers from 0 to 200.