com.mathworks.toolbox.javabuilder.MWStructArray Class
Namespace: com.mathworks.toolbox.javabuilder
Java class to manage MATLAB struct arrays
Description
Declaration
public class MWStructArray extends MWArray
The MWStructArray class manages a native MATLAB struct array.
Creation
MWStructArray()
Creates an empty struct array.
MWStructArray(int[] dims, java.lang.String[] fieldnames)
Constructs a new struct array with the specified dimensions and field names.
MWStructArray(int rows, int cols, java.lang.String[] fieldnames)
Constructs a new struct matrix with the specified number of rows and columns and field names.
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 of a Structure Array Create an MWStructArray object and display the class ID: int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); System.out.println("The class of S is " + S.classID()); The class of S is struct |
clone |
Creates and returns a deep copy of this array. Example: Cloning a Structure Array Object Create an
int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); Object C = S.clone(); System.out.println("Clone of structure S is:"); System.out.println(C.toString()); Clone of structure S is: 1x2 struct array with fields: f1 f2 f3 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:
|
fieldIndex |
Parameters:
Returns: The index of the given field name. |
fieldNames |
Returns the field names in this array. Parameters:
Returns: An array of Strings representing the field names. Example: Getting the Field Names of a Structure Array Create an MWStructArray object with three fields and display the field names: int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); String[] str = S.fieldNames(); System.out.print("The structure has the fields: "); for (int i=0; i < S.numberOfFields(); i++) System.out.print(" " + str[i]); The structure has the fields: f1 f2 f3 |
fromBean |
Throws:
|
fromMap |
Throws:
|
fromProperties |
|
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
Parameters:
Returns: Object containing the requested element. Throws:
Example: Getting Structure Array Data with get
int[] cdims = {1, 3}; MWStructArray C = new MWStructArray(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 |
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:
|
get |
Returns
the element at the specified 1-based index-array and field name 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:
|
get |
Returns
the element at the specified 1-based offset and field name in this array. The
returned element is converted to a Java array using default conversion rules.
Calling this method is equivelent to calling Parameters:
Returns: Object containing the requested element. Throws:
|
getData |
Returns a 1-D array containing a copy of the data in the underlying MATLAB array. Returns: A 1-D array of
elements stored in column-wise order. Before converting, a new array is derived by
transforming the struct array into a cell array such that a n by m by ... struct
array with p fields is transformed into a p by n by m by ... cell array. Each
element in the returned array is converted to a Java array by calling
Example: Getting Structure Array Data with getData Get the data stored in all fields and indices of MWStructArray object S: int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); int count = S.numberOfElements() * S.numberOfFields(); // Initialize the structure. Integer[] val = new Integer[6]; for (int i = 0; i < count; i++) val[i] = new Integer((i+1) * 15); // Use getData to get data from the structure. System.out.println("Data read from structure array S: \n"); MWArray[] x = (MWArray[]) S.getData(); for (int i = 0; i < x.length; i++) System.out.print(" " + x[i]); Data read from structure array S: 15 30 45 60 75 90 |
getDimensions |
Returns the number of dimensions of this array. Returns: Number of dimensions. |
getField |
Returns the element at the specified 1-based offset in this array as an MWArray instance. Parameters:
Returns: An MWArray
instance representing the requested field. This MWArray reference should be
disposed by calling Throws:
|
getField |
Returns a shared copy of the element at the specified 1-based index-array in this array as an MWArray instance. Parameters:
Returns: An MWArray
instance representing the requested field. This MWArray reference should be
disposed by calling Throws:
|
getField |
Returns a shared copy of the element at the specified 1-based index-array and field name in this array as an MWArray instance. Parameters:
Returns: An MWArray
instance representing the requested field. This MWArray reference should be
disposed by calling Throws:
|
getField |
Returns a shared copy of the element at the specified 1-based offset and field name in this array as an MWArray instance. Parameters:
Returns: An MWArray
instance representing the requested field. This MWArray reference should be
disposed by calling Throws:
|
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 |
numberOfFields |
Returns the number of fields in this array. Returns: The number of fields in this array. Example: Getting the Number of Fields in a Structure Array Create an MWStructArray object with three fields and display the number of fields: int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); String[] str = S.fieldNames(); System.out.println("There are " + S.numberOfFields() + " fields in this structure."); There are 3 fields in this structure. |
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: The serialized MATLAB array data. Throws:
|
set |
Replaces the element at the specified 1-based index-array in this array with the specified element. Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based index-array and field name in this array with the specified element. Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based index-array and field name in this array with the specified element. Parameters:
Throws:
|
set |
Replaces the element at the specified 1-based offset and field name 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. Returns: An MWStructArray instance representing a shared copy of the underlying MATLAB array. Example: Making a Shared Copy of a Structure Array Object Create an MWStructArray object and then a shared copy of that object: int[]sdims={1,2}; String[]sfields={"f1","f2","f3"}; MWStructArrayS=newMWStructArray(sdims,sfields); ObjectC=S.sharedCopy(); System.out.println("SharedcopyofstructureSis:"); System.out.println(C.toString()); Shared copy of structure S is: 1x2 struct array with fields: f1 f2 f3 |
toArray |
Returns an array containing a copy of the data in the underlying MATLAB array. Returns: An array with the same dimensionality of the MATLAB array. Before converting, a new array is derived by transforming the struct array into a cell array such that a n by m by ... struct array with p fields is transformed into a p by n by m by ... cell array. Each element in the returned array is converted to a Java array by calling MWArray.toArray() on the corresponding cell. Example: Getting Structure Array Data with toArray int[] sdims = {1, 2}; String[] sfields = {"f1", "f2", "f3"}; MWStructArray S = new MWStructArray(sdims, sfields); Integer[] val = new Integer[25]; 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 < sfields.length; j++) S.set(sfields[j], i+1, val[j + (i * 3)]); Object[][][] x = (Object[][][]) S.toArray(); System.out.println(); System.out.println("Data read from structure array S \n"); for (int j = 0; j < 2; j++) for (int i = 0; i < x.length; i++) System.out.print(" " + ((int[][]) x[i][0][j])[0][0]); Data read from structure array S 0 15 30 45 60 75 |
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 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 (한국어)