Java调用Matlab函数笔记

欢迎使用Markdown编辑器写博客

笔记是记录通过java如何调用matlab函数:
1.在命令行中输入deploytool
这里写图片描述
2.点击上图中标有红框的部分
3.选择javapackage,依次填写name,classname
这里写图片描述
在package的过程中可能会出现mcc错误的情况,参考如下解决方法: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);//第一个参数是返回结果的个数,第二个参数是实际参数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值