com.mathworks.toolbox.javabuilder.MWCharArray Class
Namespace: com.mathworks.toolbox.javabuilder
Java class to manage MATLAB character arrays
Description
Declaration
public class MWCharArray extends MWArray
Implemented Interfaces: Disposable
,
java.io.Serializable
, java.lang.Cloneable
,
java.lang.Comparable
Direct Known Subclasses: ,
Class Attributes: ,
Creation
Constructors
MWCharArray()
Creates an empty char array.
MWCharArray(char val)
Constructs a new char array that represents the primitive char argument.
MWCharArray(java.lang.Object val)
Constructs a char array that represents the Object
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. Example: Getting the Class ID of a Character Array Create an MWCharArray object and then display the class ID: char[] chArray1 = {'H', 'e', 'l', 'l', 'o'}; MWCharArray A = new MWCharArray(chArray1); System.out.println("The class of A is " + A.classID()); The class of A is char Returns:
|
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 Character Array Object Create a clone of MWCharArray object A as follows: char[] chArray = {'H', 'e', 'l', 'l', 'o'}; MWCharArray A = new MWCharArray(chArray); Object C = A.clone(); System.out.println("Clone of matrix A is:"); System.out.println(C.toString()); Clone of matrix A is: Hello 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:
|
get |
Returns the element at the specified 1-based offset in this array. Specified by:
Parameters:
Returns: Object containing the requested element. Throws:
|
get |
Returns the element at the specified 1-based index-array in this array. Specified by:
Parameters:
Returns: Object containing the requested element. Throws:
|
getChar |
Returns the character at the specified 1-based offset. Parameters:
Returns: Value of the requested element. Throws:
|
getCell |
Returns the character at the specified 1-based index-array. Example: Getting Character Array Data with getChar Use getChar to display the string stored in MWCharArray object A as follows: char[] chArray = {'H', 'e', 'l', 'l', 'o'}; MWCharArray A = new MWCharArray(chArray); for (int i = 1; i <= 5; i++) System.out.print(A.getChar(i)); Hello 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, getData returns the real part. If the underlying array is a cell or struct array, toArray is recursively called on each cell. Specified by: getData in class MWArray 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 |
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 char array with the specified dimensions. The elements of the array are all initialized to 0. Example: Constructing a Character Array Object with newInstance Create an MWCharArray object containing the text Hello: int[] dims = {1, 5}; char[] chArray = {'H', 'e', 'l', 'l', 'o'}; String str = new String(chArray); MWCharArray A = MWCharArray.newInstance(dims, str); System.out.println("The array string is \"" + A + "\""); The array string is "Hello" Parameters:
Returns: A new MWCharArray with the specified dimensions. Throws:
|
newInstance |
Constructs a char array with the specified dimensions and initializes the array with the supplied data. The input array must be of type char[] or java.lang.String. The characters in the array are assumed to be stored in column-major order. Parameters:
Returns: A new MWCharArray with the specified dimensions and 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 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. Specified by:
Parameters:
Throws:
|
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 character at the specified 1-based offset in this array with the specified char value. Parameters:
Throws:
|
set |
Replaces the character at the specified 1-based index-array in this array with the specified char value. Example: Setting Values in a Character Array Display a phrase stored in MWCharArray object A, change one of the characters, and then display the modified phrase as follows: char[] chArray = {'G', 'a', 'r', 'y'}; MWCharArray A = new MWCharArray(chArray); System.out.println(" I think " + A + " lives here." + "\n"); System.out.println("Changing the first character to M ...\n"); int[] index = {1, 1}; A.set(index, 'M'); System.out.println(" I think " + A + " lives here." + "\n"); I think Gary lives here. I think Mary lives here. 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 Character Array Object Create a shared copy of MWCharArray object A as follows: char[] chArray = {'H', 'e', 'l', 'l', 'o'}; MWCharArray A = new MWCharArray(chArray); Object S = A.sharedCopy(); System.out.print("Shared copy of matrix A is \"" + S.toString() + "\""); Shared copy of matrix A is "Hello" Returns: An MWCharArray 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. 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. |
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
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes 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)