com.mathworks.toolbox.javabuilder.MWStructArray 类
命名空间: com.mathworks.toolbox.javabuilder
用于管理 Java 结构体数组的 MATLAB 类
描述
声明
public class MWStructArray extends MWArray
MWStructArray 类管理一个本机 MATLAB® 结构体数组。
创建对象
MWStructArray()
创建一个空的结构体数组。
MWStructArray(int[] dims, java.lang.String[] fieldnames)
构造具有指定维度和字段名称的新的结构体数组。
MWStructArray(int rows, int cols, java.lang.String[] fieldnames)
构造一个具有指定行数、列数和字段名称的新的结构矩阵。
属性
公共属性
一种方便、高效且一致的方式来表示空数组,如下所示:
public static final MWArray EMPTY_ARRAY
方法
applyVisitor |
此方法是抽象的,返回由类型参数<T>指定的类型。它以 参数:
返回:
|
classID |
返回此数组的 MATLAB 类型。 参数:
返回:为 MWStructArray 返回 示例:获取结构体数组的类 ID 创建 MWStructArray 对象并显示类 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 |
创建并返回此数组的深层副本。 示例:克隆结构体数组对象 创建一个 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 返回: 抛出:
|
columnIndex |
返回一个数组,包含底层 MATLAB 数组中每个元素的列索引。 指定方:MWArray 类中的 返回:索引数组。 |
compareTo |
将此数组与指定数组进行比较以确定其顺序。 指定方:MWArray 类中的 指定者: 参数:
|
deserialize |
从序列化数据创建一个新的 MWArray。 参数:
返回:反序列化的 MWArray。 |
dispose |
释放此数组包含的原生 MATLAB 数组。 指定者: Disposable 接口中的 指定方:MWArray 类中的 |
equals |
指示其他数组是否与此数组相等。 指定方:MWArray 类中的 抛出:
|
fieldIndex |
参数:
返回:给定字段名称的索引。 |
fieldNames |
返回此数组中的字段名称。 参数:
返回:代表字段名称的字符串数组。 示例:获取结构体数组的字段名称 创建一个具有三个字段的 MWStructArray 对象并显示字段名称: 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 |
抛出:
|
fromMap |
抛出:
|
fromProperties |
|
get |
返回此数组中指定从 1 开始的偏移量的元素。返回的元素使用默认转换规则转换为 Java® 数组。调用此方法等效调用 参数:
返回:包含所请求元素的对象。 抛出:
示例:使用 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 |
返回此数组中指定的基于 1 的索引数组处的元素。返回的元素使用默认转换规则转换为 Java 数组。调用此方法等效调用 参数:
返回:包含所请求元素的对象。 抛出:
|
get |
返回此数组中指定的基于 1 的索引数组和字段名称处的元素。返回的元素使用默认转换规则转换为 Java 数组。调用此方法等效调用 参数:
返回:包含所请求元素的对象。 抛出:
|
get |
返回此数组中位于指定的以 1 为基础的偏移量和字段名称处的元素。返回的元素使用默认转换规则转换为 Java 数组。调用此方法等效调用 参数:
返回:包含所请求元素的对象。 抛出:
|
getData |
返回一个一维数组,其中包含底层 MATLAB 数组中数据的副本。 返回:按列顺序存储的元素的一维数组。转换之前,先通过将结构体数组转换为元胞数组来派生出一个新数组,这样,将具有 p 个字段的、大小为 m、... 的结构体数组转换为 ap、n、m、...元胞数组。通过在相应元胞上调用 示例:使用 getData 获取结构体数组数据 获取 MWStructArray 对象 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 |
返回此数组的维数。 返回:维度数。 |
getField |
将此数组中位于指定的基于 1 的偏移量的元素作为 MWArray 实例返回。 参数:
返回:代表所请求字段的 MWArray 实例。应通过调用 抛出:
|
getField |
将此数组中指定的基于 1 的索引数组处的元素的共享副本作为 MWArray 实例返回。 参数:
返回:代表所请求字段的 MWArray 实例。应通过调用 抛出:
|
getField |
以 MWArray 实例的形式返回此数组中指定的基于 1 的索引数组和字段名称处的元素的共享副本。 参数:
返回:代表所请求字段的 MWArray 实例。应通过调用 抛出:
|
getField |
将此数组中位于指定的基于 1 的偏移量和字段名称处的元素的共享副本作为 MWArray 实例返回。 参数:
返回:代表所请求字段的 MWArray 实例。应通过调用 抛出:
|
hashCode |
返回此数组的哈希码值。 由以下指定: |
isEmpty |
测试此数组是否没有元素。 由以下指定: 返回:如果为空则 |
isSparse |
测试此数组是否稀疏。 由以下指定: 返回:如果为空则 |
maximumNonZeros |
返回稀疏数组的分配容量。如果基础数组是非稀疏的,则此方法返回与 由以下指定: 返回:当前分配的稀疏数组中的非零元素的数量。 |
numberOfDimensions |
返回此数组的维数。 由以下指定: 返回:维数 |
numberOfElements |
返回此数组中元素的总数。 由以下指定: 返回:元素的数量 |
numberOfFields |
返回此数组中的字段数。 返回:该数组中的字段数量。 示例:获取结构体数组中的字段数 创建一个具有三个字段的 MWStructArray 对象并显示字段的数量: 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 |
返回稀疏数组中非零元素的数量。如果基础数组是非稀疏的,则此方法返回与 由以下指定: 返回:稀疏数组中当前非零元素的数量。 |
readResolve |
从字节流加载新数组时由序列化机制调用。此方法验证正确的数组类型。 返回:返回此对象,指示已验证的数组类型。 抛出:
|
rowIndex |
返回一个数组,包含底层 MATLAB 数组中每个元素的行索引。 由以下指定: 返回:索引数组。 |
serialize |
将 MATLAB 数组序列化为字节数组。 返回:序列化的 MATLAB 数组数据。 抛出:
|
set |
用指定元素替换此数组中指定的基于 1 的索引数组处的元素。 参数:
抛出:
|
set |
用指定元素替换此数组中指定的基于 1 的索引数组和字段名称处的元素。 参数:
抛出:
|
set |
用指定元素替换此数组中指定的基于 1 的索引数组和字段名称处的元素。 参数:
抛出:
|
set |
用指定元素替换此数组中位于指定基于 1 的偏移量和字段名称处的元素。 参数:
抛出:
|
setData |
由以下指定: |
sharedCopy |
创建并返回此数组的一个共享副本。共享副本指向与原始数组相同的底层 MATLAB 数组。更改共享副本中的数据也会更改原始数组。 返回:一个 MWStructArray 实例,表示底层 MATLAB 数组的共享副本。 示例:创建结构体数组对象的共享副本 创建一个 MWStructArray 对象,然后创建一个该对象的共享副本: 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 |
返回一个数组,其中包含底层 MATLAB 数组中的数据副本。 返回:与 MATLAB 数组具有相同维度的数组。转换之前,先通过将结构体数组转换为元胞数组来派生出一个新数组,这样,将具有 p 个字段的、大小为 m、... 的结构体数组转换为 ap、n、m、...元胞数组。通过在相应的单元上调用 MWArray.toArray(),返回数组中的每个元素都会转换为 Java 数组。 示例:使用 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 |
返回此数组的字符串表示形式。 由以下指定: |
validate |
验证内部数组句柄。由构造函数和反序列化代码调用。 |
从类 com.mathworks.toolbox.javabuilder.MWArray 继承的方法:
disposeArray |
此方法会销毁输入对象中包含的任何 MATLAB 原生数组并释放它们占用的内存。这是类的静态方法,因此不需要引用类的实例来调用。如果输入对象实现了 示例:构造 MWNumericArray 对象 MWArray[] MArr = new MWArray[10];
for (int i = 0; i < 10; i++)
MArr[i] = new MWNumericArray();
MWArray.disposeArray(MArr);参数:
|
从类 java.lang.Object 继承的方法。
finalize |
当垃圾回收确定没有更多对此对象的引用时,由垃圾回收器对该对象调用。 |
getClass |
返回此对象的运行时类。 |
notify |
|
notifyAll |
唤醒正在等待此对象的监视器的所有线程。 |
wait |
使当前线程等待,直到另一个线程调用此对象的 |
示例
MWStructArray S = new MWStructArray();
System.out.println("Structure array S: " + S);Structure array S: []
String[] sfields = {"f1", "f2", "f3"};
int[] dims = new int[]{1,2};
MWStructArray S = new MWStructArray(dims, sfields);
Structure array S: 1x2 struct array with fields:
f1
f2
f3
int rows = 1, cols = 2;
String[] sfields = {"f1", "f2", "f3"};
MWStructArray S = new MWStructArray(rows, cols, sfields);
System.out.println("Structure array S: " + S);版本历史记录
在 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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)