public class MWLogicalArray extends MWArray
MWLogicalArray class manages a native MATLAB logical array.EMPTY_ARRAY| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
applyVisitor(AbstractMWArrayVisitor<T> v) |
MWClassID |
classID()
Returns the MATLAB type of this array.
|
java.lang.Object |
clone()
Creates and returns a deep copy of this array.
|
int[] |
columnIndex()
Returns an array containing the column index of each element in the underlying MATLAB array.
|
int |
compareTo(java.lang.Object obj)
Compares this array with the specified array for order.
|
static MWArray |
deserialize(byte[] data)
Create a new MWArray from serialized data.
|
void |
dispose()
Frees the native MATLAB array contained by this array.
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other array is equal to this one.
|
java.lang.Object |
get(int index)
Returns the element at the specified 1-based offset in this array.
|
java.lang.Object |
get(int[] index)
Returns the element at the specified 1-based index-array in this array.
|
boolean |
getBoolean(int index)
Returns the boolean at the specified 1-based offset.
|
boolean |
getBoolean(int[] index)
Returns the boolean at the specified 1-based index-array.
|
java.lang.Object |
getData()
Returns a 1-D array containing a copy of the data in the underlying MATLAB array.
|
int[] |
getDimensions()
Returns an array containing the size of each dimension of this array.
|
int |
hashCode()
Returns a hash code value for this array.
|
boolean |
isEmpty()
Tests if this array has no elements.
|
boolean |
isSparse()
Tests if this array is sparse.
|
int |
maximumNonZeros()
Returns the allocated capacity of a sparse array.
|
static MWLogicalArray |
newInstance(int[] dims)
Constructs a logical array with the specified dimensions.
|
static MWLogicalArray |
newInstance(int[] dims,
java.lang.Object data)
Constructs a logical array with the specified dimensions and initializes the array with the supplied data.
|
static MWLogicalArray |
newSparse(int[] rowindex,
int[] colindex,
java.lang.Object data)
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.
|
static MWLogicalArray |
newSparse(int[] rowindex,
int[] colindex,
java.lang.Object data,
int rows,
int cols)
Constructs a sparse logical matrix with the specified number of rows and columns,
and initializes the array with the supplied data.
|
static MWLogicalArray |
newSparse(int[] rowindex,
int[] colindex,
java.lang.Object data,
int rows,
int cols,
int nzmax)
Constructs a sparse logical matrix with the specified number of rows and columns,
maximum nonzero elements, and initializes the array with the supplied data.
|
static MWLogicalArray |
newSparse(int rows,
int cols,
int nzmax)
Constructs a sparse logical matrix with no nonzero elements.
|
static MWLogicalArray |
newSparse(java.lang.Object arr)
Constructs a sparse logical matrix from the supplied full matrix.
|
int |
numberOfDimensions()
Returns the number of dimensions of this array.
|
int |
numberOfElements()
Returns the total number of elements in this array.
|
int |
numberOfNonZeros()
Returns the number of non-zero elements in a sparse array.
|
protected java.lang.Object |
readResolve()
Called by serialization mechanism when loading a new array from a byte stream.
|
int[] |
rowIndex()
Returns an array containing the row index of each element in the underlying MATLAB array.
|
byte[] |
serialize()
Serialize the MATLAB array to a byte array.
|
void |
set(int[] index,
boolean element)
Replaces the element at the specified 1-based index-array in this array with the specified boolean value.
|
void |
set(int[] index,
java.lang.Object element)
Replaces the element at the specified 1-based index-array in this array with the specified element.
|
void |
set(int index,
boolean element)
Replaces the element at the specified 1-based offset in this array with the specified boolean value.
|
void |
set(int index,
java.lang.Object element)
Replaces the element at the specified 1-based offset in this array with the specified element.
|
void |
setData(java.lang.Object data) |
java.lang.Object |
sharedCopy()
Creates and returns a shared copy of this array.
|
java.lang.Object[] |
toArray()
Returns an array containing a copy of the data in the underlying MATLAB array.
|
java.lang.String |
toString()
Returns a string representation of this array.
|
protected void |
validate()
Validates the internal array handle.
|
disposeArraypublic MWLogicalArray()
public MWLogicalArray(boolean val)
val - The value to initialize the array with.
boolean[][] Adata = {{true, false, false},
{false, true, false}};
MWLogicalArray A = new MWLogicalArray(Adata);
public MWLogicalArray(double val)
val - The value to initialize the array with.public MWLogicalArray(float val)
val - The value to initialize the array with.public MWLogicalArray(byte val)
val - The value to initialize the array with.public MWLogicalArray(short val)
val - The value to initialize the array with.public MWLogicalArray(int val)
val - The value to initialize the array with.public MWLogicalArray(long val)
val - The value to initialize the array with.public MWLogicalArray(java.lang.Object val)
val - The value to initialize the array with.java.lang.ArrayStoreException - A non-character or non-String array type was specified.public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
MWLogicalArray instance representing a deep copy of the
underlying MATLAB array.
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());
When run, the example displays this output:
Clone of logical matrix A is:
1 0 0
0 1 0
java.lang.CloneNotSupportedException - - The object's class does not implement the Cloneable interface.public java.lang.Object sharedCopy()
MWLogicalArray instance representing a shared copy of the
underlying MATLAB array.
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());
When run, the example displays this output:
Shared copy of logical matrix A is:
1 0 0
0 1 0
public void set(int index,
boolean element)
index - The index of the element to replace. Valid range: 1 <= index <= N, where N = total number of elements in the array.element - New value to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public void set(int[] index,
boolean element)
index - Array of indices specifying the location of the element to replace.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.element - New value to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.
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");
When run, the example displays this output:
Array element A(2,3) is false
Setting A(2,3) to true
Array element A(2,3) is true
public boolean getBoolean(int index)
index - The index of the requested element. Valid range: 1 <= index <= N, where N = total number of elements in the array.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public boolean getBoolean(int[] index)
index - Array of indices specifying the location of the requested element.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.
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));
When run, the example displays this output:
A(2,2) = true
public MWClassID classID()
MWClassID.LOGICAL for MWLogicalArray.
boolean[][] Adata = {{true, false, false},
{false, true, false}};
MWLogicalArray A = new MWLogicalArray(Adata);
System.out.println("Class of A is " + A.classID());
When run, the example displays this output:
Class of A is logical
public <T> T applyVisitor(AbstractMWArrayVisitor<T> v)
protected void validate()
public static MWLogicalArray newInstance(int[] dims)
dims - Array of dimension sizes. Each dimension size must be non-negative.MWLogicalArray with the specified dimensions.java.lang.NegativeArraySizeException - A negative dimension size is supplied.
boolean[] Adata = { true, true, false, false, true};
int[] dims = {1, 5};
MWLogicalArray A = MWLogicalArray.newInstance(dims, Adata);
System.out.println("Array A: " + A.toString());
When run, the example displays this output:
Array A: 1 1 0 0 1
public static MWLogicalArray newInstance(int[] dims, java.lang.Object data)
dims - Array of dimension sizes. Each dimension size must be non-negative.data - Data to initialize the array with.MWLogicalArray with the specified dimensions and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative dimension size is supplied.java.lang.ArrayStoreException - Non-numeric or non-boolean data is supplied.public static MWLogicalArray newSparse(int[] rowindex, int[] colindex, java.lang.Object data, int rows, int cols, int nzmax)
rowindex - Array of 1-based row indeces.colindex - Array of 1-based column indeces.data - Data to initialize the real part of the array with.rows - Number of rows in the matrix.cols - Number of columns in the matrix.nzmax - Maximum number of nonzero elements.MWLogicalArray with the specified size and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative row or column size is supplied.java.lang.ArrayStoreException - An incompatable array type or invalid array data was specified.java.lang.IndexOutOfBoundsException - An invalid row or column index was specified.
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());
When run, the example displays this output:
(1,1) 1
(1,2) 1
(1,5) 1
public static MWLogicalArray newSparse(int[] rowindex, int[] colindex, java.lang.Object data, int rows, int cols)
rowindex - Array of 1-based row indeces.colindex - Array of 1-based column indeces.data - Data to initialize the real part of the array with.rows - Number of rows in the matrix.cols - Number of columns in the matrix.MWLogicalArray with the specified size and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative row or column size is supplied.java.lang.ArrayStoreException - An incompatable array type or invalid array data was specified.java.lang.IndexOutOfBoundsException - An invalid row or column index was specified.public static MWLogicalArray newSparse(int[] rowindex, int[] colindex, java.lang.Object data)
rowindex - Array of 1-based row indeces.colindex - Array of 1-based column indeces.data - Data to initialize the real part of the array with.MWLogicalArray with the specified size and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative row or column size is supplied.java.lang.ArrayStoreException - An incompatable array type or invalid array data was specified.java.lang.IndexOutOfBoundsException - An invalid row or column index was specified.public static MWLogicalArray newSparse(int rows, int cols, int nzmax)
rows - Number of rows in the matrix.cols - Number of columns in the matrix.nzmax - Maximum number of nonzero elements.MWLogicalArray with the specified size and initialized with the supplied data.java.lang.NegativeArraySizeException - A negative row or column size is supplied.public static MWLogicalArray newSparse(java.lang.Object arr)
arr - Array to convert.MWLogicalArray initialized with the supplied data.java.lang.ArrayStoreException - An incompatable array type or invalid array data was specified.public byte[] serialize()
public static MWArray deserialize(byte[] data)
data - serialized array returned from MWArray.serializepublic int numberOfDimensions()
numberOfDimensions in class MWArraypublic int[] getDimensions()
getDimensions in class MWArraypublic boolean isEmpty()
public boolean isSparse()
public boolean equals(java.lang.Object obj)
public int compareTo(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
public int numberOfElements()
numberOfElements in class MWArraypublic int numberOfNonZeros()
numberOfElements().numberOfNonZeros in class MWArraypublic int maximumNonZeros()
numberOfElements().maximumNonZeros in class MWArraypublic void dispose()
dispose in interface Disposabledispose in class MWArraypublic java.lang.Object get(int index)
public java.lang.Object get(int[] index)
get in class MWArrayindex - Array of indices specifying the location of the requested element.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public void set(int index,
java.lang.Object element)
public void set(int[] index,
java.lang.Object element)
set in class MWArrayindex - Array of indices specifying the location of the element to replace.
The length of the index array must be exactly the number of dimensions of this array.
Each element of the index array has the valid range: 1 <= index[i] <= N[i], where N[i] = the size of the ith dimension.element - New element to replace at index.java.lang.IndexOutOfBoundsException - An invalid index has been supplied.public java.lang.Object[] toArray()
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.public java.lang.Object getData()
getData returns
the real part. If the underlying array is a cell or struct array, toArray is
recursively called on each cell.getData in class MWArraynumberOfElements() for a non-sparse array, and numberOfNonZeros()
for a sparse array.public int[] rowIndex()
public int[] columnIndex()
columnIndex in class MWArrayprotected java.lang.Object readResolve()
throws java.io.ObjectStreamException
java.io.InvalidObjectException - Attempt to load an invalid array handle.java.io.ObjectStreamException© 1994-2008 The MathWorks, Inc. Terms of Use Patents Trademarks