MATLAB 中的 .NET 数据类型
当您调用 .NET 方法或函数时,MATLAB 会自动将大多数原始 MATLAB 参数转换为 .NET 类型。要传递字符串数组,请使用 cell
函数。要传递其他 MATLAB 类型的数组,请使用 NET.createArray
函数。您不能将结构体数组、稀疏数组或复数传递给 .NET 方法。
MATLAB 会自动将原始的 .NET 返回类型转换为等价的 MATLAB 类型(如果存在)。要转换 System.String
对象,请调用 char
函数。如果 .NET 函数返回数组,则在使用 MATLAB 命令中的数据之前,请对矩形数组使用对应的 MATLAB 数值函数,或者对交错数组使用 cell
函数。要将 MATLAB 字典转换为对应的 .NET 对象,请调用 NET.createDictionary
函数。
函数
NET.createArray | 非原生 .NET 类型数组 |
NET.createDictionary | Generic .NET Dictionary (自 R2023a 起) |
NET.disableAutoRelease | 锁定表示运行时可调用包装器(COM 包装器)的 .NET 对象 |
NET.enableAutoRelease | 解锁表示运行时可调用包装器(COM 包装器)的 .NET 对象 |
主题
- Pass Data to .NET Objects
MATLAB converts method arguments into .NET types.
- Handle Data Returned from .NET Objects
Mapping C# .NET types to MATLAB types.
- Pass Numeric Arguments
MATLAB automatically converts .NET numeric data to and from equivalent MATLAB data.
- Pass System.String Arguments
Examples using
System.String
arguments. - Pass Cell Arrays of .NET Data
Tips for working with contents of nested
System.Object
arrays in MATLAB. - 读取 Excel 电子表格数据的元胞数组
此示例适用于 Microsoft® .NET Framework,说明如何将 Microsoft Excel® 电子表格数据的列转换为 MATLAB 类型。MATLAB 将一系列 .NET 值作为
System.Object[,]
类型进行读取。使用cell
函数将System.String
值转换为 MATLAB 字符数组,将System.DateTime
值转换为datetime
对象。 - Pass System.Enum Arguments
Examples using
System.Enum
arguments. - Pass System.Nullable Arguments
This example shows how to handle .NET methods with
System.Nullable
type arguments, whose underlying value type isdouble
. - Pass Jagged Arrays
This example shows how to create a .NET jagged array of
System.Double
using theNET.createArray
function. - Convert Nested System.Object Arrays
This example shows how to use the
cell
function to convert data in nestedSystem.Object
arrays. - Use Arrays with .NET Applications
MATLAB automatically converts arrays to .NET types, as described in the MATLAB Primitive Type Conversion Table.
- Convert .NET Arrays to Cell Arrays
Use the
cell
function to convertSystem.String
andSystem.Object
arrays to MATLAB cell arrays.
疑难解答
Limitations to Support of .NET Arrays
.NET features not supported in MATLAB.