Package com.stata.sfi
Class Mata
java.lang.Object
com.stata.sfi.Mata
This class provides access to global Mata matrices. All methods are not
thread-safe unless otherwise stated.
Example:
public static int printMataMatrix(String[] args) {
String name = args[0];
long numCol = Mata.getMataColTotal(name);
long numRow = Mata.getMataRowTotal(name);
if (Mata.isTypeReal(name)) {
for (long i = 0; i < numRow; i++) {
for (long j = 0; j < numCol; j++) {
double value = Mata.getMataRealAt(name, i, j);
String index = "[" + (i + 1) + ", " + (j + 1) + "]";
SFIToolkit.displayln(index + " = " + value);
}
}
}
else {
String type = Mata.getMataEltype(name);
SFIToolkit.errorln("Matrix is type " + type + "; real expected");
return (3250);
}
return 0;
}
From Stata...
. mata
// matrix must be global for sfi.Mata to access
mat = (1, 3, 5 \ 5, 6, 4)
. end
. javacall Examples printMataMatrix, jar(examples.jar) args(mat)
[1, 1] = 1.0
[1, 2] = 3.0
[1, 3] = 5.0
[2, 1] = 5.0
[2, 2] = 6.0
[2, 3] = 4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]getComplexAt(double[] matrix, int colCount, int row, int col) Get an element from a previously returned matrix.static voidgetComplexValues(double[] complex, Double real, Double imaginary) Get the real and imaginary parts from a complex result.static longgetMataColTotal(String name) Get the number of columns in a Mata matrix.static double[]getMataCompAt(String name, long row, long col) Read a complex Mata matrix element.static StringgetMataEltype(String name) Get the type of a Mata object.static doublegetMataRealAt(String name, long row, long col) Read a real Mata matrix element.static longgetMataRowTotal(String name) Get the number of rows in a Mata matrix.static StringgetMataStringAt(String name, long row, long col) Read a string Mata matrix element.static booleanisTypeComplex(String name) Determine if the matrix type is complex.static booleanisTypeReal(String name) Determine if the matrix type is real.static booleanisTypeString(String name) Determine if the matrix type is string.
-
Method Details
-
getComplexAt
Get an element from a previously returned matrix.- Parameters:
matrix- The matrix.colCount- The number of columns in the matrix. This value can be obtained fromgetMataColTotal().row- Zero-based row number.col- Zero-based column number.- Returns:
- The element; a double[2] containing the matrix element.
-
getComplexValues
Get the real and imaginary parts from a complex result. -
getMataColTotal
Get the number of columns in a Mata matrix.- Parameters:
name- Name of the Mata matrix.- Returns:
- The number of columns. Returns -1 if an error occurs.
-
getMataCompAt
Read a complex Mata matrix element.- Parameters:
name- Name of the Mata matrix.row- Zero-based row number.col- Zero-based column number.- Returns:
- A double[2] containing the matrix element. Returns null if an error occurs.
-
getMataEltype
Get the type of a Mata object. -
getMataRealAt
Read a real Mata matrix element.- Parameters:
name- Name of the Mata matrix.row- Zero-based row number.col- Zero-based column number.- Returns:
- The element. Returns a Stata missing if an error occurs.
-
getMataRowTotal
Get the number of rows in a Mata matrix.- Parameters:
name- Name of the Mata matrix.- Returns:
- The number of rows. Returns -1 if an error occurs.
-
getMataStringAt
Read a string Mata matrix element. -
isTypeComplex
Determine if the matrix type is complex.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is complex.
-
isTypeReal
Determine if the matrix type is real.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is real.
-
isTypeString
Determine if the matrix type is string.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is string.
-