com.mathworks.matlab.exceptions.UnsupportedTypeException
Java 异常,表示在 Java 到 MATLAB 的数据转换中遇到了不支持的数据类型
自 R2026a 起
描述
UnsupportedTypeException 是一个异常,表示 Java® 和 MATLAB® 数据类型之间的类型转换失败。当 MATLAB Runtime 遇到无法在 Java 和 MATLAB 环境之间正确转换的输入或输出数据类型时,会抛出此异常。
该异常会在以下几种关键情况下发生:
当通过
feval()或fevalAsync()方法将 Java 对象传递给 MATLAB 函数时,如果这些对象的类型无法转换为 MATLAB 数据类型。从 MATLAB 函数获取结果时,MATLAB 类型的输出无法转换为预期的 Java 类型。
示例
public class Example {
public static void main(String[] args) {
String ctfPath = "C:/path/to/your/ctf";
try (MatlabRuntime runtime = MatlabRuntime.startMatlab(ctfPath)) {
// Create an object of unsupported type (Thread is not convertible to MATLAB)
Thread currentThread = Thread.currentThread();
// Attempt to pass unsupported type to MATLAB function
runtime.feval(0, "disp", currentThread);
} catch (UnsupportedTypeException e) {
// Handle unsupported type conversion
System.out.println("Data type conversion error: " + e.getMessage());
} catch (MatlabNotAvailableException | InterruptedException |
IllegalArgumentException | IllegalStateException e) {
System.out.println("Runtime error: " + e.getMessage());
}
}
}
版本历史记录
在 R2026a 中推出