public final class Matrix extends Object
public static int printMatrix(String args[]) {
String name = args[0];
double[] matrix = Matrix.getMatrix(name);
int cols = Matrix.getMatrixCol(name);
int rows = Matrix.getMatrixRow(name);
if (cols == 0 || rows == 0) {
SFIToolkit.errorln("Empty matrix");
return 503;
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
double element = Matrix.getAt(matrix, cols, i, j);
SFIToolkit.displayln("[" + (i + 1) + ", " + (j + 1) + "] = "
+ element);
}
}
return 0;
}
| Modifier and Type | Method and Description |
|---|---|
static int |
convertSymmetricToStd(String name)
Convert a symmetric matrix to a standard matrix.
|
static int |
createMatrix(String name,
int rows,
int cols,
double initialValue)
Create a Stata matrix.
|
static int |
createMatrix(String name,
int rows,
int cols,
double initialValue,
boolean isSymmetric)
Create a Stata matrix.
|
static double |
getAt(double[] matrix,
int colCount,
int row,
int col)
Access an element of a previously obtained Stata matrix in the form of a
one-dimensional array.
|
static double[] |
getMatrix(String name)
Get the data in a Stata matrix.
|
static int |
getMatrixCol(String name)
Get the number of columns in a Stata matrix.
|
static String[] |
getMatrixColNames(String name)
Get the column names of a Stata matrix.
|
static int |
getMatrixRow(String name)
Get the number of rows in a Stata matrix.
|
static String[] |
getMatrixRowNames(String name)
Get the row names of a Stata matrix.
|
static int |
setMatrixColNames(String name,
String[] colNames)
Set the column names of a Stata matrix.
|
static int |
setMatrixRowNames(String name,
String[] rowNames)
Set the row names of a Stata matrix.
|
static int |
storeMatrixAt(String name,
int row,
int col,
double val)
Store an element in an existing Stata matrix.
|
@Synchronized public static int convertSymmetricToStd(String name)
name - Name of the matrix.@Synchronized public static int createMatrix(String name, int rows, int cols, double initialValue)
name - Name of the matrix to create.rows - Number of rows.cols - Number of columns.initialValue - An initialization value for each element.@Synchronized public static int createMatrix(String name, int rows, int cols, double initialValue, boolean isSymmetric)
name - Name of the matrix to create.rows - Number of rows.cols - Number of columns.initialValue - An initialization value for each element.isSymmetric - Mark the matrix as symmetric. If the number of rows
and columns are not equal, this parameter will be
ignored. This parameter affects the behavior of
storeMatrixAt(). When the matrix is marked as
symmetric,
storeMatrixAt() will always maintain symmetry.@Synchronized public static double getAt(double[] matrix, int colCount, int row, int col)
matrix - The matrix in the form of a one-dimensional array.colCount - The number of columns. This value can be obtained by
calling getMatrixCol().row - Zero-based row number.col - Zero-based column number.@Synchronized public static double[] getMatrix(String name)
getAt() to obtain elements of the
returned array.name - Name of the Stata matrix.@Synchronized public static int getMatrixCol(String name)
name - Name of the Stata matrix.@Synchronized public static String[] getMatrixColNames(String name)
name - Name of the Stata matrix.String array containing the column names of the matrix.
Returns null if an error occurs.@Synchronized public static int getMatrixRow(String name)
name - Name of the Stata matrix.@Synchronized public static String[] getMatrixRowNames(String name)
name - Name of the Stata matrix.String array containing the row names of the matrix.
Returns null if an error occurs.@Synchronized public static int setMatrixColNames(String name, String[] colNames)
name - Name of the Stata matrix.colNames - A String array containing the column names for
the matrix. The array length must match the number of
columns in the matrix.@Synchronized public static int setMatrixRowNames(String name, String[] rowNames)
name - Name of the Stata matrix.rowNames - A String array containing the row names for the
matrix. The array length must match the number of rows in
the matrix.@Synchronized public static int storeMatrixAt(String name, int row, int col, double val)
name - Name of the matrix.row - Zero-based row number.col - Zero-based column number.val - Value.