com.mathworks.toolbox.javabuilder.MWCellArray Class
Namespace: com.mathworks.toolbox.javabuilder
Java class to manage MATLAB cell arrays
Description
Declaration
public class MWCellArray extends MWArray
The MWCellArray class manages a native MATLAB cell array
Implemented Interfaces: Disposable
,
java.io.Serializable
, java.lang.Cloneable
,
java.lang.Comparable
Direct Known Subclasses: ,
Class Attributes: ,
Creation
Constructors
MWCellArray()
MWCellArray(int[] dims)
MWCellArray(int rows, int cols)
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:
|
asList |
Provide a java.util.List interface to the cell array. Each item in the list is an MWArray or some subclass. List.set can take any object type, however. This operation is equivalent to MWCellArray.set. Returns: array as list |
classID |
Returns the MATLAB type of this array. 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()); Class of C is cell |
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 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()); Clone of cell array C is: [] [] [] 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:
Parameters:
|
exportCells |
Export the cells to a java.util.List of Java native type array objects. List.get will convert the stored MWArray to a Java native array by calling MWArray.toArray. Otherwise the List returned by this method behaves the same as one returned by MWCellArray.asList. Returns: cells as list |
get |
Returns
the element at the specified 1-based offset in this array. The returned element is
converted to a Java array using default conversion rules. Calling this method is
equivalent to calling
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]); } B: Cell data C(1,3) is 15 Parameters:
Returns: Object containing the requested element. Throws:
|
get |
Returns
the element at the specified 1-based index-array in this array. The returned
element is converted to a Java array using default conversion rules. Calling this
method is equivalent to calling
Parameters:
Returns: Object containing the requested element. Throws:
|
getCell |
Returns a shared copy of the element at the specified 1-based offset in this array as an MWArray instance. Parameters:
Returns: An MWArray
instance representing the requested cell. This MWArray reference should be
disposed by calling Throws:
|
getCell |
Returns a shared copy of the element at the specified 1-based index-array in this array as an MWArray instance. Example: Parameters:
Returns: An MWArray instance representing the requested cell. This MWArray reference should be dsiposed by calling MWArray.dispose(). Throws:
|
getData |
Returns a 1-D array containing a copy of the data in the underlying MATLAB array. 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(); Data read from cell array C: 0 0 0 Returns: A 1-D array of elements stored in column-wise order. Each
element in the returned array is converted to a Java array by calling
|
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. |
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: Serialized MATLAB array data Throws:
|
set |
Replaces the element at the specified 1-based offset in this array with the specified element. 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()); Cell data C(1,3) is 15 Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based index-array in this array with the specified element. 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. 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()); Shared copy of cell array C is: [] [] [] Returns: An MWCellArray instance representing a shared copy of the underlying MATLAB array. |
toArray |
Returns an array containing a copy of the data in the underlying MATLAB array. 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]); Data read from cell array C [] [] [] Returns: An array with the same dimensionality of the MATLAB array. Each element in the returned array is converted to a Java array by calling MWArray.toArray() on the corresponding cell. |
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 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
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)