com.mathworks.matlab.exceptions.MatlabNotAvailableException
Java 异常,表示 MATLAB Runtime 不可用或无法启动
自 R2026a 起
描述
MatlabNotAvailableException 是一个异常,表示无法访问或初始化 MATLAB® Runtime。此异常继承自 java.util.concurrent.ExecutionException,并作为关键信号,表明 MATLAB Runtime 无法用于计算。
该异常会在以下几种关键情况下抛出:
当尝试通过
startMatlab()或startMatlabAsync()启动 MATLAB Runtime 实例时,运行时无法启动。当 MATLAB 客户端已通过
terminateMatlabClient()方法终止时。当 MATLAB 客户端无法正确初始化时。
当尝试通过 close() 方法关闭 MATLAB Runtime 实例时,运行时未能正常退出。
示例
public class Example {
public static void main(String[] args) {
String ctfPath = "C:/path/to/your/ctf";
try (MatlabRuntime runtime = MatlabRuntime.startMatlab(ctfPath)) {
// Execute MATLAB function
double[][] result = runtime.feval(1, "mymagic", 3);
// Print results
for (double[] row : result) {
System.out.println(Arrays.toString(row));
}
} catch (MatlabNotAvailableException e) {
// Handle case where MATLAB Runtime is not available
System.out.println("MATLAB Runtime could not be started or terminated: " + e.getMessage());
} catch (InterruptedException e) {
System.out.println("Operation was interrupted: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore interrupted status
} catch (IllegalArgumentException | IllegalStateException e) {
// These can also be thrown by startMatlab
System.out.println("Invalid arguments or state: " + e.getMessage());
} catch (UnsupportedTypeException e) {
// This can be thrown by feval
System.out.println("Unsupported type in function call: " + e.getMessage());
}
}
}版本历史记录
在 R2026a 中推出