ConcatRows
ConcatRows( A ; rowIndex,colIndex, ,concatIndex )
Takes an array, A indexed by rowIndex and colIndex, and concatenates each row, henceforth flattening the array by one dimension. The result is indexed by concatIndex, which must be an index with Size(rowIndex) * Size(colIndex) elements.
As of Analytica 4.2, concatIndex is optional. If not specified, ConcatRows creates a local index with the name .ConcatIndex to dimension the result.
Library
In Analytica 4.2 and later, this function is a built-in function, in the Array library.
In Analytica 4.0 and 4.1, this function is located in the "Concatenation.ana" library. To use that function, you must add the library to your model.
Examples
Let
A:= |
|
---|
ConcatRows(A,I,J) | → |
|
ConcatRows(A,J,I) | → |
|
To flatten three dimensions, I1, I2 and I3, use:
- Var tmp := ConcatRows(A,I1,I2) Do ConcatRows(tmp,tmp.ConcatIndex,I3)
Inverse of ConcatRows
It is often useful to perform the inverse of ConcatRows -- in otherwords, starting with a 1-D array indexed by K
, un-flatten it to a 2-D array indexed by I
and J
. As with ConcatRows, K
must have Size(I)*Size(J)
elements. The inverse is accomplished with:
Function UnconcatRows( X : Array[K] ; I,J,K : Index ) Definition: X[K=(@I-1)*Size(J) + @J]
With this inverse function, you can extend a variety of 1-D transformation functions to 2-D equivalents. For example, Rank(X,I)
returns the sort rank of each element in X
. The following obtains the rank among all elements in a 2-D array, A
:
Var B := ConcatRows(A,I,J); LocalAlias K := Handle(B.ConcatIndex); UnconcatRows( Rank(B,K), I,J,K )
Some other 1-D transformation functions that can be usefully extended to 2-D equivalents in this fashion include: Sort, Cumulate, Uncumulate, CumProduct, Dispatch, GetFract, and perhaps others. The technique could be applied to the Integrate, Cdf, Pdf, LinearInterp and CubicInterp functions, but in these cases, this would not be the same as what you would normally think of as the 2-D generalization of the functions, so use with care in those cases.
Enable comment auto-refresher