Matrix creation |
Algorithms - Matrices | |||
Written by Jan Schulz | |||
Sunday, 13 July 2008 20:10 | |||
Creating a matrix of defined dimensions After declaration of a variable of the type t2dVariantArrayDouble the dynamic arrays have zero length and no information can be stored in the record structure. Thus, accessing arrays results in a runtime error. Here a function is introduced that initialises a rectangular matrix of given dimensions for a declared variable of the type t2dVariantArrayDouble. Elements of the matrix are initialised with a predefined value.
Algorithm First the name of the matrix is set. Thereafter the desired dimensions of the row and column tile arrays of are set according to passed parameters. To create the matrix the dimension of the row array is initialised first. Perpendicular to the matrix rows the column arrays are set for the elements of the matrix. Each element is initialised with the demanded value.
Source Function mtx_Create (Var OutputMatrix : T2dVariantArrayDouble; SizeY, SizeX : Integer; InitialValue : Double; MatrixName :String) : Boolean;
Example The below example creates and initialises a defined matrix for the variable aMatrix of the type t2dVariantArrayDouble with six rows and three columns. All elements aMatrix.Cells of the matrix are initialised with the value zero. The dimension of the array aMatrix.RowTitle is set to six and that of aMatrix.ColTitle to three. Fields of the respective arrays contain empty strings. The name aMatrix.MatrixName is set to ‘Example matrix’: Procedure CreateNewMatrix;
// use the matrix
|
|||
Last Updated on Friday, 18 March 2011 18:03 |