.
3ss.cn

Java调用Matlab函数方法

1.在命令行中输入deploytool

2.点击上图中标有红框的部分

3.选择javapackage,依次填写name,classname

在package的过程中可能会出现mcc错误的情况

4.编写java类,进行测试

import com.mathworks.toolbox.javabuilder.MWException;
import computef.ComputeF;
public class matlab2javaTest {
public static void main(String args[]) throws MWException {
System.out.println( System.getProperty("java.library.path"));
ComputeF cl = new ComputeF();
cl.computef(0);
}
}

第一次运行时,会报如下错误

Exception in thread “main” java.lang.UnsatisfiedLinkError: Failed to find the library mclmcrrt7_14.dll, required by MATLAB Builder JA, on java.library.path.
This library is typically installed along with MATLAB or the MCR, its absence may indicate an issue with that installation or the current path configuration.
The MCR version that this component is trying to use is: 7.14.

错误原因可能是:path中没有matlab的路径,即找不到mclmcrrt7_14.dll这个文件,添加matlab路径到path中就可以了

5.调用有返回结果的函数

m文件内容:

function [f,c]=computef(key) 

调用computerf函数时

Object[] result = null;
result = cl.computef(2,0);//第一个参数是返回结果的个数,第二个参数是实际参数
赞(0)
未经允许不得转载:互联学术 » Java调用Matlab函数方法

评论 抢沙发