com.mathworks.toolbox.javabuilder.MWLogicalArray Class
Namespace: com.mathworks.toolbox.javabuilder
Java class to manage MATLAB logical arrays
Description
Declaration
public class MWLogicalArray extends MWArray
The MWLogicalArray class manages a native MATLAB logical array
Implemented Interfaces:
MWComponentOption
, java.io.Serializable
,
java.lang.Cloneable
, java.lang.Comparable
Creation
Constructors
MWLogicalArray()
Creates an empty logical array.
MWLogicalArray(boolean val)
Constructs a new scalar logical array that represents the primitive boolean argument.
MWLogicalArray(byte val)
Constructs a new scalar logical array that represents the primitive byte argument.
MWLogicalArray(double val)
Constructs a new scalar logical array that represents the primitive double argument.
MWLogicalArray(float val)
Constructs a new scalar logical array that represents the primitive float argument.
MWLogicalArray(int val)
Constructs a new scalar logical array that represents the primitive int argument.
MWLogicalArray(long val)
Constructs a new scalar logical array that represents the primitive long argument.
MWLogicalArray(java.lang.Object val)
Constructs a logical array that represents the Object argument.
MWLogicalArray(short val)
Constructs a new scalar logical array that represents the primitive short argument.
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. Parameters:
Returns: returns
Example: Getting the Class ID for a Logical Array Object Return the class ID for boolean[][] Adata = {{true, false, false}, {false, true, false}}; MWLogicalArray A = new MWLogicalArray(Adata); System.out.println("Class of A is " + A.classID()); Class of A is logical |
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 Logical Array Object Create a clone of
boolean[][] Adata = {{true, false, false}, {false, true, false}}; MWLogicalArray A = new MWLogicalArray(Adata); Object C = A.clone(); System.out.println("Clone of logical matrix A is:"); System.out.println(C.toString()); Clone of logical matrix A is: 1 0 0 0 1 0 Returns: An 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:
|
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:
Throws:
|
get |
Returns the element at the specified 1-based offset in this array. Parameters:
Returns: Object containing the requested element. Throws:
|
get |
Returns the element at the specified 1-based index-array in this array. Parameters:
Returns: Object containing the requested element. Throws:
|
getBoolean |
Returns the boolean at the specified 1-based offset. Parameters:
Returns: Value of the requested element. Throws:
|
getBoolean |
Returns the boolean at the specified 1-based index-array. Example: Getting a Boolean Value from a Logical Array boolean[][] Adata = {{true, false, false}, {false, true, false}}; MWLogicalArray A = new MWLogicalArray(Adata); int[] index = {2, 2}; System.out.println("A(2,2) is " + A.getBoolean(index)); A(2,2) = true Parameters:
Returns: Value of the requested element. Throws:
|
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,
Specified by:
Returns: A 1-D array of elements stored in column-wise order. The length of the returned array equals numberOfElements() for a non-sparse array, and numberOfNonZeros() for a sparse array. |
getDimensions |
Returns an array containing the size of each dimension of this array. Specified by:
Returns: Array containing size of each dimension. |
hashCode |
Returns a hash code value for this array. Specified
by:
|
isEmpty |
Tests if this array has no elements. Specified by:
Returns:
|
isSparse |
Tests if this array is sparse. 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 logical array with the specified dimensions. The elements of the array are all initialized to false. Example: Constructing a Logical Array Object with newInstance Construct a 1-by-5 logical array using the newInstance method. Note that data in the Java array must be stored in a column-wise order so that it will be in row-wise order in the final MWLogicalArray object. boolean[] Adata = { true, true, false, false, true}; int[] dims = {1, 5}; MWLogicalArray A = MWLogicalArray.newInstance(dims, Adata); System.out.println("Array A: " + A.toString()); Array A: 1 1 0 0 1 Parameters:
Returns: A new MWLogicalArray with the specified dimensions. Throws:
|
newInstance |
Constructs a logical 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. If a numeric type is provided, each non-zero array element is converted to true, and false otherwise. Parameters:
Returns: A new MWLogicalArray with the specified dimensions and initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse logical 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. Example: Constructing a Sparse Logical Array Object Create a sparse array of logical values using the newSparse method: boolean[] Adata = {true, true, false, false, true}; int[] ri = {1, 1, 1, 1, 1}; int[] ci = {1, 2, 3, 4, 5}; MWLogicalArray A = MWLogicalArray.newSparse(ri, ci, Adata); System.out.println(A.toString()); (1,1) 1 (1,2) 1 (1,5) 1 Parameters:
Returns: A new sparse MWLogicalArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse logical 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. Parameters:
Returns: A new sparse MWLogicalArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse logical 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. Parameters:
Returns: A new sparse MWLogicalArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse logical matrix with no nonzero elements. Parameters:
Returns: A new sparse MWLogicalArray with the specified size and initialized with the supplied data. Throws:
|
newSparse |
Constructs a sparse logical matrix from the supplied full matrix. Parameters:
Returns: A new sparse MWLogicalArray initialized with the supplied data. 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
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. |
readResolve |
Called by serialization mechanism when loading a new array from a byte stream. This method validates the correct array type. Parameters:
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 element at the specified 1-based index-array in this array with the specified boolean value. Parameters:
Throws:
Example: Setting a Value in a Logical Array Get and modify the value at A(2,3): boolean[][] Adata = {{true, false, false}, {false, true, false}}; MWLogicalArray A = new MWLogicalArray(Adata); int[] index = {2, 3}; Object d_out = A.get(index); System.out.println("Array element A(2,3) is " + d_out.toString() + "\n"); System.out.println("Setting A(2,3) to true\n"); A.set(index, true); d_out = A.get(index); System.out.println("Array element A(2,3) is " + d_out.toString() + "\n"); Array element A(2,3) is false Setting A(2,3) to true Array element A(2,3) is true |
set |
Replaces the element at the specified 1-based index-array in this array with the specified element. Specified by:
Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based offset in this array with the specified boolean value. Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based offset in this array with the specified element. Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based index-array in this array with the specified element. Specified by:
Parameters:
Throws:
|
setData |
Specified by:
|
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. Returns:
An Example: Making a Shared Copy of a Logical Array Object Create a shared copy of
boolean[][] Adata = {{true, false, false}, {false, true, false}}; MWLogicalArray A = new MWLogicalArray(Adata); Object C = A.sharedCopy(); System.out.println("Shared copy of logical matrix A is:"); System.out.println(C.toString()); Shared copy of logical matrix A is: 1 0 0 0 1 0 |
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,
Specified by:
Returns: An array with the same dimensionality of the MATLAB array. |
toString |
Returns a string representation of this array. Specified
by:
|
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
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
|
Version History
Introduced in R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)