public class MWCellArray extends MWArray
MWCellArray
class manages a native MATLAB cell array.EMPTY_ARRAY
Constructor and Description |
---|
MWCellArray()
Creates an empty cell array.
|
MWCellArray(int[] dims)
Constructs a new cell array with the specified dimensions.
|
MWCellArray(int rows,
int cols)
Constructs a new cell matrix with the specified number of rows and columns.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
applyVisitor(AbstractMWArrayVisitor<T> v) |
java.util.List<MWArray> |
asList()
Provide a java.util.List interface to the cell array.
|
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.util.List<java.lang.Object> |
exportCells()
Export the cells to a java.util.List of Java native type array objects.
|
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.
|
MWArray |
getCell(int index)
Returns a shared copy of the element at the specified 1-based offset in this array as an
MWArray instance. |
MWArray |
getCell(int[] index)
Returns a shared copy of the element at the specified 1-based index-array in this array as an
MWArray instance. |
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.
|
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,
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,
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.
|
disposeArray
public MWCellArray()
Example: Constructing an Empty Cell Array Object
This example creates an empty MWCellArray object:MWCellArray C = new MWCellArray(); System.out.println("C = " + C.toString());When run, the example displays this output:
C = []
public MWCellArray(int[] dims)
dims
- Array of dimension sizes. Each dimension size must be non-negative.java.lang.NegativeArraySizeException
- A negative dimension size is supplied.
Example: Constructing an Initialized Cell Array Object
This example constructs and initializes a 2-by-3 MWCellArray object:int[] cdims = {2, 3}; MWCellArray C = new MWCellArray(cdims); Integer[] val = new Integer[6]; for (int i = 0; i < 6; i++) val[i] = new Integer(i * 15); for (int i = 0; i < 2; i++) for (int j = 0; j < 3; j++) { int[] idx = {i+1, j+1}; C.set(idx, val[j + (i * 3)]); } System.out.println("C = " + C.toString());When run, the example displays this output:
C = [ 0] [15] [30] [45] [60] [75]
public MWCellArray(int rows, int cols)
rows
- Number of rows. Number of rows must be non-negative.cols
- Number of columns. Number of columns must be non-negative.java.lang.NegativeArraySizeException
- A negative row or column size is supplied.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
MWCellArray
instance representing a deep copy of the
underlying MATLAB array.
Example: Cloning a Cell Array Object
Create an MWCellArray object and then a clone of that object:int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); Object X = C.clone(); System.out.println("Clone of cell array C is:"); System.out.println(X.toString());When run, the example displays this output:
Clone of cell array C is: [] [] []
java.lang.CloneNotSupportedException
- - The object's class does not implement the Cloneable interface.public java.lang.Object sharedCopy()
MWCellArray
instance representing a shared copy of the
underlying MATLAB array.
Example: Making a Shared Copy of a Cell Array Object
Create an MWCellArray object and then a shared copy of that object:int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); Object X = C.sharedCopy(); System.out.println("Shared copy of cell array C is:"); System.out.println(X.toString());When run, the example displays this output:
Shared copy of cell array C is: [] [] []
public MWClassID classID()
MWClassID.CELL
for MWCellArray
.
Example: Getting the Class ID of a Cell Array
Create an MWCellArray object and display its class:int[] cdims = {2, 3}; MWCellArray C = new MWCellArray(cdims); System.out.println("Class of C is " + C.classID());When run, the example displays this output:
Class of C is cell
public void set(int index, java.lang.Object 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 element to replace at index. If element is of type MWArray
, the cell
at index is set to a shared copy of the underlying MATLAB array. Otherwise, a new MATLAB array is created
from element using default conversion rules and assigned to the cell at index.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.
Example: Setting Values in a Cell Array
Set the value of the MWCellArray object C at index (1,3):int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); Integer val = new Integer(15); int[] index = {1, 3}; C.set(index, val); Object x = C.get(index); System.out.println("Cell data C(1,3) is " + x.toString());When run, the example displays this output:
Cell data C(1,3) is 15
public void set(int[] index, java.lang.Object 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 element to replace at index. If element is of type MWArray
, the cell
at index is set to a shared copy of the underlying MATLAB array. Otherwise, a new MATLAB array is created
from element using default conversion rules and assigned to the cell at index.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public java.lang.Object get(int index)
getCell(index).toArray()
.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.
Example: Getting Data from a Cell Array with get
int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); Integer val = new Integer(15); int[] index2 = {1, 3}; C.set(index2, val); Object x = C.get(index2); if (x instanceof int[][]) { int[][] y = (int[][])x; System.out.println("B: Cell data C(1,3) is " + y[0][0]); }When run, the example displays this output:
B: Cell data C(1,3) is 15
public java.lang.Object get(int[] index)
getCell(index).toArray()
.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.public MWArray getCell(int index)
MWArray
instance.index
- The index of the requested element. Valid range: 1 <= index <= N, where N = total number of elements in the array.MWArray
instance representing the requested cell. This MWArray
reference
should be dsiposed by calling MWArray.dispose()
.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public MWArray getCell(int[] index)
MWArray
instance.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.MWArray
instance representing the requested cell. This MWArray
reference
should be dsiposed by calling MWArray.dispose()
.java.lang.IndexOutOfBoundsException
- An invalid index has been supplied.public java.lang.Object getData()
MWArray.toArray()
on
the corresponding cell.
Example: Getting Cell Array Data with getData
Use getData to read data from MWCellArray object C:int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); Integer[] val = new Integer[3]; for (int i = 0; i < 3; i++) val[i] = new Integer(i * 15); for (int i = 1; i <= 3; i++) C.set(i, val[i-1]); System.out.println("Data read from cell array C: \n"); MWArray[] x = (MWArray[]) C.getData(); for (int i = 0; i < x.length; i++) System.out.println(x[i]); System.out.println();When run, the example displays this output:
Data read from cell array C: 0 0 0
public java.lang.Object[] toArray()
MWArray.toArray()
on
the corresponding cell.
Example: Getting Cell Array Data with toArray
int[] cdims = {1, 3}; MWCellArray C = new MWCellArray(cdims); System.out.println("Data read from cell array C \n"); Object x = (Object) C.toArray(); System.out.println(); for (int i = 0; i < x[0].length; i++) System.out.println(x[0][i]);When run, the example displays this output:
Data read from cell array C [] [] []
public <T> T applyVisitor(AbstractMWArrayVisitor<T> v)
protected void validate()
public java.util.List<MWArray> asList()
public java.util.List<java.lang.Object> exportCells()
public byte[] serialize() throws java.io.IOException
java.io.IOException
- if the array cannot be serialized. For
example, executable content (function handles, class instances) cannot
be serialized.public static MWArray deserialize(byte[] data)
data
- serialized array returned from MWArray.serializepublic int numberOfDimensions()
numberOfDimensions
in class MWArray
public int[] getDimensions()
getDimensions
in class MWArray
public 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 MWArray
public int numberOfNonZeros()
numberOfElements()
.numberOfNonZeros
in class MWArray
public int maximumNonZeros()
numberOfElements()
.maximumNonZeros
in class MWArray
public void dispose()
dispose
in interface Disposable
dispose
in class MWArray
public int[] rowIndex()
public int[] columnIndex()
columnIndex
in class MWArray
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.InvalidObjectException
- Attempt to load an invalid array handle.java.io.ObjectStreamException
© 1994-2017 The MathWorks, Inc. Patents Trademarks