com.mathworks.toolbox.javabuilder.MWNumericArray Class
Namespace: com.mathworks.toolbox.javabuilder
Java class to manage numeric arrays in MATLAB
Description
Declaration
public class MWNumericArray extends MWArray
The MWNumericArray class is the base class for all numeric MATLAB array types
Implemented Interfaces: Disposable
,
java.io.Serializable
, java.lang.Cloneable
,
java.lang.Comparable
Creation
Constructors
MWNumericArray()
Creates an empty MWNumericArray of type MWClassID.DOUBLE
.
MWNumericArray(boolean rVal, boolean iVal, MWClassID classid)
Constructs a complex numeric double array that represents the primitive boolean arguments.
MWNumericArray(boolean rVal, MWClassID classid)
Constructs a real scalar numeric array that represents the primitive boolean argument.
MWNumericArray(byte rVal)
Constructs a real scalar numeric array of type MWClassID.INT8 that represents the primitive byte argument.
MWNumericArray(byte rVal, byte iVal)
Constructs a complex scalar numeric array of type MWClassID.INT8 that represents the primitive byte arguments.
MWNumericArray(byte rVal, byte iVal, MWClassID classid)
Constructs a complex scalar numeric array that represents the primitive byte arguments.
MWNumericArray(byte rVal, MWClassID classid)
Constructs a real scalar numeric array that represents the primitive byte argument.
MWNumericArray(double rVal)
Constructs a real scalar array of type MWClassID.DOUBLE that represents the primitive double argument.
MWNumericArray(double rVal, double iVal)
Constructs a complex scalar array of type MWClassID.DOUBLE that represents the primitive double arguments.
MWNumericArray(double rVal, double iVal, MWClassID classid)
Constructs a complex scalar array that represents the primitive double arguments.
MWNumericArray(double rVal, MWClassID classid)
Constructs a real scalar array that represents the primitive double argument.
MWNumericArray(float rVal)
Constructs a real scalar numeric array of type MWClassID.SINGLE that represents the primitive float argument.
MWNumericArray(float rVal, float iVal)
Constructs a complex scalar numeric array of type MWClassID.SINGLE that represents the primitive float arguments.
MWNumericArray(float rVal, float iVal, MWClassID classid)
Constructs a complex scalar numeric array that represents the primitive float arguments.
MWNumericArray(float rVal, MWClassID classid)
Constructs a real scalar numeric array that represents the primitive float argument.
MWNumericArray(int rVal)
Constructs a real scalar numeric array of type MWClassID.INT32 that represents the primitive int argument.
MWNumericArray(int rVal, int iVal)
Constructs a complex scalar numeric array of type MWClassID.INT32 that represents the primitive int arguments.
MWNumericArray(int rVal, int iVal, MWClassID classid)
Constructs a complex scalar numeric array that represents the primitive int arguments.
MWNumericArray(int rVal, MWClassID classid)
Constructs a real scalar numeric array that represents the primitive int argument.
MWNumericArray(long rVal)
Constructs a real scalar numeric array of type MWClassID.INT64 that represents the primitive long argument.
MWNumericArray(long rVal, long iVal)
Constructs a complex numeric double array of type MWClassID.INT64 that represents the primitive long arguments.
MWNumericArray(long rVal, long iVal, MWClassID classid)
Constructs a complex numeric double array that represents the primitive long arguments.
MWNumericArray(MWClassID classid)
Creates an empty MWNumericArray of the specified type.
MWNumericArray(java.lang.Object rVal)
Constructs a real numeric array that represents the Object argument using default conversion rules.
MWNumericArray(java.lang.Object rVal, MWClassID classid)
Constructs a real numeric array that represents the Object argument.
MWNumericArray(java.lang.Object rVal, java.lang.Object iVal)
Constructs a complex numeric array that represents the Object arguments using default conversion rules.
MWNumericArray(java.lang.Object rVal, java.lang.Object iVal, MWClassID classid)
Constructs a complex numeric array that represents the Object arguments.
MWNumericArray(short rVal)
Constructs a real scalar numeric array of type MWClassID.INT16 that represents the primitive short argument.
MWNumericArray(short rVal, MWClassID classid)
Constructs a real scalar numeric array that represents the primitive short argument.
MWNumericArray(short rVal, short iVal)
Constructs a complex scalar numeric array of type MWClassID.INT16 that represents the primitive short arguments.
MWNumericArray(short rVal, short iVal, MWClassID classid)
Constructs a complex scalar numeric array that represents the primitive short arguments.
Properties
Public Properties
EMPTY_ARRAY
— Represent an empty array
public static final MWArray
A convenient, efficient, and consistent way to represent an empty array as follows:
public static final MWArray EMPTY_ARRAY
Methods
Public Methods
applyVisitor |
This
method is abstract and returns a type specified by the type parameter <T>.
It takes an instance of Parameters:
Returns:
|
classID |
Returns the MATLAB type of this array. Specified
by:
Returns: MWClassID of this array |
clone |
Creates and returns a deep copy of this array. Changing the data in a deep copy does not change the original array. Example: Cloning a Numeric Array Object Create a 3-by-6 array of type
double[][] AData = {{ 1, 2, 3, 4, 5, 6}, { 7, 8 , 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}}; MWNumericArray A = new MWNumericArray(AData, MWClassID.DOUBLE); Object C = A.clone(); System.out.println("Clone of matrix A is:"); System.out.println(C.toString()); Clone of matrix A is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Clone of matrix A is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Returns: An MWNumericArray instance representing a deep copy of the underlying MATLAB array. Throws:
|
columnIndex |
Returns an array containing the column index of each element in the underlying MATLAB array. Specified by:
Returns: Array of indices. |
compareTo
|
Compares this array with the specified array for order. Specified by:
Specified by:
Parameters:
|
complexity | Specified
by:
Specified by:
Parameters:
|
deserialize |
Create a new MWArray from serialized data. Parameters:
Returns: the deserialized MWArray |
dispose |
Frees the native MATLAB array contained by this array. Specified
by:
Specified
by:
|
equals |
Indicates whether some other array is equal to this one. Specified by:
Parameters:
|
get |
Returns the element at the specified 1-based offset in this array. Specified by:
Parameters:
Returns: Object containing the requested element. Throws:
|
get |
Return this array as a scalar byte. Specified
by:
Parameters:
Returns: Object containing the requested element. Throws:
|
getByte |
Return this array as a scalar byte. Returns: Scalar value. |
getByte |
Returns the real part at the specified 1-based offset as a byte value. Example: Getting a Short Value from a Numeric Array The following examples use this array: short[][] Adata = {{ 1, 2, 3, 4, 5, 6}, { 7, 8 , 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}}; MWNumericArray A = new MWNumericArray(Adata, MWClassID.INT16); int[] index = {2, 4}; System.out.println("A(2,4) = " + A.getShort(index)); A(2,4) = 10 Example: Using get and set on a Numeric Array Given the same MWNumericArray used in the previous example, get and then modify the value of element (2, 3): int[] idx = {2, 3}; System.out.println("A(2, 3) is " + A.get(idx).toString()); System.out.println(""); System.out.println("Setting A(2, 3) to a new value ..."); A.set(idx, 555); System.out.println(""); System.out.println("A(2, 3) is now " + A.get(idx).toString()); A(2, 3) is 9.0 A(2, 3) is now 555.0 Parameters:
Returns: Value of the requested element. Throws:
|
getByte |
Returns the real part at the specified 1-based index-array as a byte value. Parameters:
Returns: Value of the requested element. Throws:
|
getByteData |
This method returns a one-dimensional array of Java types matching the primitive type byte. For example, if you call getByteData, an array of type byte is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of elements of the Java primitive type byte |
getData |
Returns a 1-D array containing a copy of the data in the underlying MATLAB array. The elements of the returned array are converted according to default conversion rules. If the underlying MATLAB array is a complex numeric type, getData returns the real part. If the underlying array is a cell or struct array, toArray is recursively called on each cell. Specified
by:
Parameters: Returns: A 1-D array
of elements stored in column-wise order. The length of the returned array equals
|
getDimensions |
Returns an array containing the size of each dimension of this array. Specified by:
Returns: Array containing size of each dimension |
getDouble |
Return this array as a scalar double. Returns: Scalar value. |
getDouble |
Returns the real part at the specified 1-based offset as a double value. Parameters:
Returns: Value of the requested element. Throws:
|
getDouble |
Returns the real part at the specified 1-based index-array as a double value. Example:
Parameters:
Returns: Value of the requested element. Throws:
|
getDoubleData |
This
method returns a one-dimensional array of Java types matching the primitive type
double. For example, if you call Returns: One-dimensional array of elements of the Java primitive type double |
getEps |
Returns
MATLAB's concept of Returns:
|
getFloat |
Return this array as a scalar float. Returns: Scalar value |
getFloat |
Returns the real part at the specified 1-based offset as a float value. Parameters:
Returns: Value of the requested element. Throws:
|
getFloat |
Returns the real part at the specified 1-based index-array as a float value. Parameters:
Returns: Value of the requested element. Throws:
|
getFloatData |
This method returns a one-dimensional array of Java types matching the primitive type float. For example, if you call getFloatData, an array of type float is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of elements of the Java primitive type float |
getImag |
Returns the imaginary part at the specified 1-based offset in this array. Example: Getting the Real and Imaginary Parts of an Array Start by creating a two-dimensional array of complex values: double[][] Rdata = {{ 2, 3, 4}, { 8 , 9, 10}, {14, 15, 16}}; double[][] Idata = {{ 6, 5, 14}, { 7 , 1, 23}, { 1, 1, 9}}; MWNumericArray A = new MWNumericArray(Rdata, Idata, MWClassID.DOUBLE); System.out.println("Complex matrix A ="); System.out.println(A.toString()); 2.0000 + 6.0000i 3.0000 + 5.0000i 4.0000 + 14.0000i 8.0000 + 7.0000i 9.0000 + 1.0000i 10.0000 + 23.0000i 14.0000 + 1.0000i 15.0000 + 1.0000i 16.0000 + 9.0000i getImag to read the real and imaginary parts of the element
at index (2, 3):int[] index = {2, 3}; System.out.println("The real part of A(2,3) = " + A.get(index)); System.out.println("The imaginary part of A(2,3) = " + A.getImag(index)); The real part of A(2,3) = 10.0 The imaginary part of A(2,3) = 23.0 Parameters:
Returns: Object containing the requested element. Throws:
|
getImag |
Returns the imaginary part at the specified 1-based index-array in this array. Parameters:
Returns: Object containing the requested element. Throws:
|
getImagByte |
Return imaginary component of this array as a scalar byte. Returns: Scalar value |
getImagByte |
Returns the imaginary part at the specified 1-based offset as a byte value. Example:
Parameters:
Returns: Value of the requested element. Throws:
|
getImagByte |
Returns the imaginary part at the specified 1-based index-array as a byte value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagByteData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type byte. For example, if you call getImagByteData, an array of type byte is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type byte. |
getImagData |
Returns a 1-D array containing a copy of the imaginary data in the underlying MATLAB array. Example: Getting Data from a Complex Array Start by creating a two-dimensional array of complex values: double[][] Rdata = {{ 2, 3, 4}, { 8 , 9, 10}, {14, 15, 16}}; double[][] Idata = {{ 6, 5, 14}, { 7 , 1, 23}, { 1, 1, 9}}; MWNumericArray A = new MWNumericArray(Rdata, Idata, MWClassID.DOUBLE); System.out.println("Complex matrix A ="); System.out.println(A.toString()); 2.0000 + 6.0000i 3.0000 + 5.0000i 4.0000 + 14.0000i 8.0000 + 7.0000i 9.0000 + 1.0000i 10.0000 + 23.0000i 14.0000 + 1.0000i 15.0000 + 1.0000i 16.0000 + 9.0000i int[] index = {2, 3}; double[] x; System.out.println("The real data in matrix A is:"); x = (double[]) A.getData(); for (int i = 0; i < x.length; i++) System.out.print(" " + x[i]); System.out.println(); System.out.println(); System.out.println("The imaginary data in matrix A is:"); x = (double[]) A.getImagData(); for (int i = 0; i < x.length; i++) System.out.print(" " + x[i]); System.out.println(); The real data in matrix A is: 2.0 8.0 14.0 3.0 9.0 15.0 4.0 10.0 16.0 The imaginary data in matrix A is: 6.0 7.0 1.0 5.0 1.0 1.0 14.0 23.0 9.0 Returns: A 1-D array of elements stored in column-wise order. The elements of the returned array are converted according to default conversion rules. |
getImagDouble |
Return imaginary component of this array as a scalar double. Returns: Scalar value |
getImagDouble |
Returns the imaginary part at the specified 1-based offset as a double value. Example: Getting Complex Data of a Specific Type Start by creating a two-dimensional array of complex values: double[][] Rdata = {{ 2, 3, 4}, { 8 , 9, 10}, {14, 15, 16}}; double[][] Idata = {{ 6, 5, 14}, { 7 , 1, 23}, { 1, 1, 9}}; MWNumericArray A = new MWNumericArray(Rdata, Idata, MWClassID.DOUBLE); System.out.println("Complex matrix A ="); System.out.println(A.toString()); 2.0000 + 6.0000i 3.0000 + 5.0000i 4.0000 + 14.0000i 8.0000 + 7.0000i 9.0000 + 1.0000i 10.0000 + 23.0000i 14.0000 + 1.0000i 15.0000 + 1.0000i 16.0000 + 9.0000i int[] index = {2, 3}; System.out.println("The real part of A(2,3) = " + A.getDouble(index)); System.out.println("The imaginary part of A(2,3) = " + A.getImagDouble(index)); The real part of A(2,3) = 10.0 The imaginary part of A(2,3) = 23.0 Parameters:
Returns: Value of the requested element. Throws:
|
getImagDouble |
Returns the imaginary part at the specified 1-based index-array as a double value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagDoubleData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type double. For example, if you call getImagDoubleData, an array of type double is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type double |
getImagFloat |
Returns the imaginary part at the specified 1-based offset as a float value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagFloat |
Returns the imaginary part at the specified 1-based offset as a float value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagFloat |
Returns the imaginary part at the specified 1-based offset as a float value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagFloatData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type float. For example, if you call getImagFloatData, an array of type float is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type float |
getImagInt |
Return imaginary component of this array as a scalar int. Returns: Scalar value |
getImagInt |
Returns the imaginary part at the specified 1-based offset as an int value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagInt |
Returns the imaginary part at the specified 1-based index-array as an int value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagIntData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type int. For example, if you call getImagIntData, an array of type int is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type int |
getImagLong |
Return imaginary component of this array as a scalar long. Returns: Scalar value |
getImagLong |
Returns the imaginary part at the specified 1-based offset as a long value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagLong |
Returns the imaginary part at the specified 1-based index-array as a long value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagLongData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type long. For example, if you call getImagLongData, an array of type long is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type long |
getImagShort |
Return imaginary component of this array as a scalar short. Returns: Scalar value |
getImagShort |
Returns the imaginary part at the specified 1-based offset as a short value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagShort |
Returns the imaginary part at the specified 1-based index-array as a short value. Parameters:
Returns: Value of the requested element. Throws:
|
getImagShortData |
This method returns a one-dimensional array of imaginary elements of the Java primitive type short. For example, if you call getImagShortData, an array of type short is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of imaginary elements of the Java primitive type short |
getInf |
Returns MATLAB's concept of Inf. Returns: Inf as a double |
getInt |
Return this array as a scalar int. Returns: Scalar value. |
getInt |
Returns the real part at the specified 1-based offset as an int value. Parameters:
Returns: Value of the requested element. Throws:
|
getInt |
Returns the real part at the specified 1-based index-array as an int value. Parameters:
Returns: Value of the requested element. Throws:
|
getIntData |
This method returns a one-dimensional array of Java types matching the primitive type int. For example, if you call getIntData, an array of type int is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of elements of the Java primitive type int Throws:
|
getLong
|
Return this array as a scalar long. Returns: Scalar value |
getLong |
Parameters:
Returns: Throws:
|
getLong |
Returns the real part at the specified 1-based index-array as a long value. Parameters:
Returns: Value of the requested element. Throws:
|
getLongData |
This method returns a one-dimensional array of Java types matching the primitive type long. For example, if you call getLongData, an array of type long is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of elements of the Java primitive type long |
getNaN |
Returns MATLAB's concept of NaN. Returns: NaN as a double. |
getShort
|
Return this array as a scalar short. Returns: Scalar value |
getShort |
Returns the real part at the specified 1-based offset as a short value. Parameters:
Returns: Value of the requested element. Throws:
|
getShort |
Returns the real part at the specified 1-based index-array as a short value. Parameters:
Returns: Value of the requested element. Throws:
|
getShortData |
This method returns a one-dimensional array of Java types matching the primitive type short. For example, if you call getShortData, an array of type short is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary. If conversion is performed, truncation or other loss of precision may occur. Returns: One-dimensional array of elements of the Java primitive type short |
hashCode |
Returns a hash code value for this array. Specified
by:
|
isEmpty |
Tests if this array has no elements. Specified by:
Parameters:
Returns:
|
isFinite |
Test for finiteness in a machine-independent manner. Example: Testing for Finite Array Values Test x for finiteness: double x = 25; if (MWNumericArray.isFinite(x)) System.out.println("The input value is finite"); The input value is finite Parameters:
Returns:
|
isInf |
Test for infinity in a machine-independent manner. Example: Test x for infinity double x = 1.0 / 0.0; if (MWNumericArray.isInf(x)) System.out.println("The input value is infinite"); The input value is infinite Parameters:
Returns:
|
isNaN |
Test for NaN in a machine-independent manner. Example: Testing for NaN Array Values Test x for NaN: double x = 0.0 / 0.0; if (MWNumericArray.isNaN(x)) System.out.println("The input value is not a number."); The input value is not a number Parameters:
Returns:
|
isSparse |
Tests if this array is sparse. Parameters:
Specified by:
Returns:
|
maximumNonZeros |
Returns the
allocated capacity of a sparse array. If the underlying array is non-sparse, this
method returns the same value as
Specified by:
Returns: Currently allocated number of non-zero elements in a sparse array. |
newInstance |
Constructs a numeric array with the specified dimensions and complexity. The elements of the array are all initialized to 0. This method offers better performance than using the class constructor. To construct an uninitialized real or complex numeric array, use the following: newInstance(int[] dims, MWClassID classid, MWComplexity cmplx) To construct and initialize a real numeric array, use: newInstance(int[] dims, Object rData, MWClassID classid) To construct and initialize a complex numeric array, use newInstance(int[] dims, Object rData, Object iData, MWClassID classid) Example: Constructing a Numeric Array Object with newInstance Construct a 3-by-6 real numeric array using the newInstance method. Note that data in the Java array must be stored in column-major order so that it will be in the correct order in the final MWNumericArray object. int[] dims = {3, 6}; double[] Adata = { 1, 7, 13, 2, 8, 14, 3, 9, 15, 4, 10, 16, 5, 11, 17, 6, 12, 18}; MWNumericArray A = MWNumericArray.newInstance(dims, Adata, MWClassID.DOUBLE); System.out.println("A = " + A); A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Parameters:
Returns: A new MWNumericArray with the specified size, type, and complexity. Throws:
|
newInstance |
Constructs a real numeric array with the specified dimensions and initializes the array with the supplied data. The input array must be a 1-D array with the data stored in column-major order. Valid types for input arrays are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, and 1-D arrays of java.lang.Boolean. Parameters:
Returns: A new MWNumericArray with the specified dimensions and type, and initialized with the supplied data. Throws:
|
newInstance |
Constructs a complex numeric array with the specified dimensions and initializes the array with the supplied data. The input arrays must be 1-D arrays with the data stored in column-major order. Valid types for input arrays are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, and 1-D arrays of java.lang.Boolean. Parameters:
Returns: A new MWNumericArray with the specified dimensions and type, and initialized with the supplied data. Throws:
|
newSparse |
Constructs a real sparse numeric matrix with the specified number of rows and columns, maximum nonzero elements, and initializes the array with the supplied data. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k), with space allocated for nzmax nonzeros. Valid types for the input array are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. To construct a Sparse Matrix with No Nonzero Elements: newSparse(int rows, int cols, int nzmax, MWClassID classid, MWComplexity cmplx) To construct a real sparse array from an existing nonsparse two-dimensional array, use: newSparse(Object realData, MWClassID classid) To construct and initialize a new real sparse array, use: newSparse(int[] rowindex, int[] colindex, Object realData, MWClassID classid) To construct and initialize a new real sparse array, specifying its dimensions, use: newSparse(int[] rowindex, int[] colindex, Object realData, int rows, int cols, MWClassID classid) To construct and initialize a new real sparse array, specifying its dimensions and maximum number of nonzeros, use: newSparse(int[] rowindex, int[] colindex, Object realData, int rows, int cols, int nzmax, MWClassID classid) To construct a complex sparse array from an existing nonsparse two-dimensional array, use: newSparse(Object realData, Object imagData, MWClassID classid) To construct and initialize a new complex sparse array, use: newSparse(int[] rowindex, int[] colindex, Object realData, Object imagData, MWClassID classid) To construct and initialize a new complex sparse array, specifying its dimensions, use: newSparse(int[] rowindex, int[] colindex, Object realData, Object imagData, int rows, int cols, MWClassID classid) To construct and initialize a new complex sparse array, specifying its dimensions and maximum number of nonzeros, use: newSparse(int[] rowindex, int[] colindex, Object realData, Object imagData, int rows, int cols, int nzmax, MWClassID classid) Example: Constructing a Sparse Array Object with newSparse To create a sparse complex MWNumericArray, construct a two-dimensional complex sparse MWNumericArray from the real and imaginary double vectors: double[][] rData = {{ 0, 0, 0, 16, 0}, {71, 63, 32, 0, 0}}; double[][] iData = {{ 0, 0, 0, 41, 0}, { 0, 0, 32, 0, 2}}; MWNumericArray A = MWNumericArray.newSparse(rData, iData, MWClassID.DOUBLE); System.out.println("A = " + A.toString()); A = (2,1) 71.0000 (2,2) 63.0000 (2,3) 32.0000 +32.0000i (1,4) 16.0000 +41.0000i (2,5) 0 + 2.0000i Example: Using newSparse with Row and Column Indices Construct a sparse MWNumericArray from vector
double[] Adata = { 0, 10, 0, 0, 40, 50, 60, 0, 0, 90}; int[] ri = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; int[] ci = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5}; MWNumericArray A = MWNumericArray.newSparse(ri, ci, Adata, MWClassID.DOUBLE); System.out.println("A = " + A.toString()); (2,1) 50 (1,2) 10 (2,2) 60 (1,5) 40 (2,5) 90 Example: Assigning Multiple Values to a Single Array Element Create a sparse MWNumericArray using the rowindex and colindex arguments, specifying multiple values for the array element at index (2, 5). The result is that this element stores the sum of the values from Adata(1), Adata(7), Adata(8), and Adata(9), which is equal to 250. double[] Adata = { 0, 10, 0, 0, 40, 50, 60, 70, 80, 90}; int[] ri = {1, 2, 1, 1, 1, 2, 2, 2, 2, 2}; int[] ci = {1, 5, 2, 3, 5, 1, 2, 5, 5, 5}; MWNumericArray A = MWNumericArray.newSparse(ri, ci, Adata, 4, 5, MWClassID.DOUBLE); System.out.println("A = " + A.toString()); (2,1) 50 (2,2) 60 (1,5) 40 (2,5) 250 Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a real sparse numeric matrix with the specified number of rows and columns, and initializes the array with the supplied data. The maximum number of nonzero elements is calculated from rData.length. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k). Valid types for the input array are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a real sparse numeric matrix with the number of rows = max{rowindex(k)} and the number of columns = max{colindex(k)}, and initializes the array with the supplied data. The maximum number of nonzero elements is calculated from rData.length. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k). Valid types for the input array are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a real sparse numeric matrix from the supplied full matrix. Currently, only numeric sparse arrays of type double are supported. Parameters:
Returns: A new sparse MWNumericArray initialized with the supplied data. Throws:
|
newSparse |
Constructs a complex sparse numeric matrix with the specified number of rows and columns, maximum nonzero elements, and initializes the array with the supplied data. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k) + iData(k)*i, with space allocated for nzmax nonzeros. Valid types for input arrays are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a complex sparse numeric matrix with the specified number of rows and columns, and initializes the array with the supplied data. The maximum number of nonzero elements is calculated from max{rData.length, iData.length}. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k) + iData(k)*i. Valid types for input arrays are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a complex sparse numeric matrix with the number of rows = max{rowindex(k)} and the number of columns = max{colindex(k)}, and initializes the array with the supplied data. The maximum number of nonzero elements is calculated from max{rData.length, iData.length}. The row and column index arrays are used to construct the sparse array such that S(rowindex(k), columnindex(k)) = rData(k) + iData(k)*i. Valid types for input arrays are: double[], float[], byte[], short[], int[], long[], boolean[], 1-D arrays of any sub-class of java.lang.Number, 1-D arrays of java.lang.Boolean, and 1-D arrays of java.lang.String. Currently, only numeric sparse arrays of type double are supported. Any elements of the data arrays that have duplicate values of rowindex and columnindex are added together. Parameters:
Returns: A new sparse MWNumericArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a complex sparse numeric matrix from the supplied full matrices. Currently, only numeric sparse arrays of type double are supported. Parameters:
Returns: A new sparse MWNumericArray initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse numeric matrix with no nonzero elements. Parameters:
Returns: A new sparse MWNumericArray with the specified size. Throws:
|
numberOfDimensions |
Returns the number of dimensions of this array. Specified by:
Returns: Number of dimensions |
numberOfElements |
Returns the total number of elements in this array. Specified by:
Returns: Number of elements. |
numberOfNonZeros |
Returns
the number of non-zero elements in a sparse array. If the underlying array is
non-sparse, this method returns the same value as
Specified by:
Returns: Current number of non-zero elements in a sparse array. |
readResolve |
Called by serialization mechanism when loading a new array from a byte stream. This method validates the correct array type. Returns: Returns this Object indicating validated array type. Throws:
|
rowIndex |
Returns an array containing the row index of each element in the underlying MATLAB array. Specified by:
Returns: Array of indices. |
serialize |
Serialize the MATLAB array to a byte array. Returns: The serialized MATLAB array data. Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified double value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified float value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified byte value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified int value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified short value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based offset in this array with the specified long value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified double value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified float value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified byte value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified int value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified short value. Parameters:
Throws:
|
set |
Replaces the real part at the specified 1-based index-array in this array with the specified long value. Parameters:
Throws:
|
setData |
Specified by:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified element. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified double value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified float value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified byte value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified int value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified short value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based offset in this array with the specified long value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified element. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified double value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified float value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified byte value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified int value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified short value. Parameters:
Throws:
|
setImag |
Replaces the imaginary part at the specified 1-based index-array in this array with the specified long value. Parameters:
Throws:
|
setImagData |
Initializes imaginary component of MATLAB array data. Parameters:
Throws:
|
sharedCopy |
Creates and returns a shared copy of this array. A shared copy points to the same underlying MATLAB array as the original. Changing the data in a shared copy also changes the original array. Parameters:
Returns: An MWNumericArray instance representing a shared copy of the underlying MATLAB array. Throws:
|
toArray |
Returns an array containing a copy of the data in the underlying MATLAB array. The returned array has the same dimensionality as the underlying MATLAB array. The elements of the returned array are converted according to default conversion rules. If the underlying MATLAB array is a complex numeric type, toArray returns the real part. If the underlying array is sparse, a full representation of the array is returned. Care should be taken when calling toArray on a sparse array with large row and column dimensions, as this action may exhaust system memory. If the underlying array is a cell or struct array, toArray is recursively called on each cell. Specified by:
Returns: An array with the same dimensionality of the MATLAB array. |
toByteArray |
Returns an array of elements of the Java primitive type byte. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toByteArray, an array of type byte is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. Returns: Array of elements of the Java primitive type byte |
toDoubleArray |
Returns an array of elements of the Java primitive type double. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toDoubleArray, an array of type double is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of elements of the Java primitive type double |
toFloatArray |
Returns an array of elements of the Java primitive type float. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toFloatArray, an array of type float is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. Example: Using toTypeArray Methods This example demonstrates how you can coerce or force data to a specified numeric type by invoking any of the toTypeArray methods. Object results = null; try { // call a compiled m-function results = myobject.myfunction(2); // first output is known to be a numeric matrix MWNumericArray resultA = (MWNumericArray) results[0]; double[][] a = resultA.toDoubleArray(); // second output is known to be a 3-dimensional numeric array MWNumericArray resultB = (MWNumericArray) results[1]; int[][][] b = resultB.toIntArray(); } finally { MWNumericArray.disposeArray(results); } Returns: Array of elements of the Java primitive type float. |
toImagArray |
Returns an array containing a copy of the imaginary data in the underlying MATLAB array. Returns: An array with the same dimensionality of the MATLAB array. The elements of the returned array are converted according to default conversion rules. Example: Getting Complex Data with toImagArray Start by creating a two-dimensional array of complex values: double[][] Rdata = {{ 2, 3, 4}, { 8 , 9, 10}, {14, 15, 16}}; double[][] Idata = {{ 6, 5, 14}, { 7 , 1, 23}, { 1, 1, 9}}; MWNumericArray A = new MWNumericArray(Rdata, Idata, MWClassID.DOUBLE); System.out.println("Complex matrix A ="); System.out.println(A.toString()); 2.0000 + 6.0000i 3.0000 + 5.0000i 4.0000 + 14.0000i 8.0000 + 7.0000i 9.0000 + 1.0000i 10.0000 + 23.0000i 14.0000 + 1.0000i 15.0000 + 1.0000i 16.0000 + 9.0000i double[][] x = (double[][]) A.toImagArray(); int[] dimA = A.getDimensions(); System.out.println("The imaginary part of matrix A is:"); for (int i = 0; i < dimA[0]; i++) { for (int j = 0; j < dimA[1]; j++) { System.out.print(" " + x[i][j]); } System.out.println(); } The imaginary part of matrix A is: 6.0 5.0 14.0 7.0 1.0 23.0 1.0 1.0 9.0 |
toImagByteArray |
Returns an array of imaginary elements of the Java primitive type byte. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagByteArray, an array of type byte is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type byte. |
toImagDoubleArray |
Returns an array of imaginary elements of the Java primitive type double. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagDoubleArray, an array of type double is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type double |
toImagFloatArray |
Returns an array of imaginary elements of the Java primitive type float. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagFloatArray, an array of type float is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type float. |
toImagIntArray |
Returns an array of imaginary elements of the Java primitive type int. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagIntArray, an array of type int is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type int. |
toImagLongArray |
Returns an array of imaginary elements of the Java primitive type long. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagLongArray, an array of type long is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type long. |
toImagShortArray |
Returns an array of imaginary elements of the Java primitive type short. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toImagShortArray, an array of type short is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of imaginary elements of the Java primitive type short. |
toIntArray |
Returns an array of elements of the Java primitive type int. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toIntArray, an array of type int is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of elements of the Java primitive type int. |
toLongArray |
Returns an array of elements of the Java primitive type long. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toLongArray, an array of type long is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of elements of the Java primitive type long. |
toShortArray |
Returns an array of elements of the Java primitive type short. The returned array is of the same dimension as the underlying MATLAB array. For example, if you call toShortArray, an array of type short is returned regardless of the data type in the underlying array. The data is converted from another primitive type, if necessary, and the array's original dimensions are preserved upon return. If conversion is performed, truncation or other loss of precision may occur. See example in toDoubleArray. Returns: Array of elements of the Java primitive type short. |
validate |
Validates the internal array handle. Called by constructors and deserialization code. |
Inherited Methods
Methods inherited from class
com.mathworks.toolbox.javabuilder.MWArray
.
disposeArray |
This
method destroys any native MATLAB arrays contained in the input object and frees
the memory occupied by them. This is a static method of the class and thus does
not need to be invoked in reference to an instance of the class. If the input
object implements the Example: Constructing an MWNumericArray Object MWArray[] MArr = new MWArray[10]; for (int i = 0; i < 10; i++) MArr[i] = new MWNumericArray(); MWArray.disposeArray(MArr); Parameters:
|
Methods inherited from class java.lang.Object
.
finalize |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
getClass |
Returns the runtime class of this Object. |
notify |
|
notifyAll |
Wakes up all threads that are waiting on this object's monitor. |
wait |
Causes
the current thread to wait until another thread invokes the
|
Examples
Hello World
Version History
Introduced in R2006a
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)