java matlab混合编程_java和matlab混合编程

1. 从matlab 2006b版本起,开始提供javabuilder工具箱,以支持向java提供编程接口。

2. 安装matlab编译Runtime: MCR(例如:MATLAB/toolbox/compiler/deploy/win64/MCRInstaller.exe)。

3. 在matlab command window中使用deploytool命令打开deploy窗口。

3.1 新建工程(将被编译为java中的一个Class)

3.2 向工程添加m文件(每个m文件将被编译为一个method)

3.3 build工程,matlab将于指定目录生成相应的jar包(例如MProj.jar)和javedoc文件。

4. 在eclipse中新建java工程,将matlab toolbox中javabuilder.jar和生成的MProj.jar置于java工程的类路径下。

5. OK,可以开始使用javabuiler.jar和MProj.jar提供的接口开始java编程了!javabuilder.jar的API javadoc可在matlab的帮助文档中查询,MProj.jar的API javadoc已在上面2.3中生成。

一个javabuilder工具箱中自带的例子:Compute Magicsquare square and print result

import com.mathworks.toolbox.javabuilder.*;

import magicsquare.*;

public class TestMatlab {

public static void main(String[] args) {

MWNumericArray n = null; /* Stores input value */

Object[] result = null; /* Stores the result */

Magicsquare theMagic = null; /* Stores magic class instance */

try {

/* If no input, exit */

if (args.length == 0)

{

System.out.println("Error: must input a positive integer");

return;

}

/* Convert and print input value */

n = new MWNumericArray(Double.valueOf(args[0]), MWClassID.DOUBLE);

System.out.println("Magic square of order " + n.toString());

/* Create new magic object */

theMagic = new Magicsquare();

/* Compute Magicsquare square and print result */

result = theMagic.makesqr(1, n);

System.out.println(result[0]);

} catch (Exception e) {

System.out.println("Exception: " + e.toString());

} finally {

/* Free native resources */

MWArray.disposeArray(n);

MWArray.disposeArray(result);

if (theMagic != null)

theMagic.dispose();

}

}

}

6. 以上步骤已经可以搞定使用matlab接口编程的大多数情况,但目前为止(我用的是2009a),貌似matlab还不能编译训练模型的函数,如时间序列模型armax(),调用java程序报错:

Undefined function or method 'armax' for input arguments of type 'iddata'.

不知该如何在java中使用armax()这样的函数,企求高手不吝指点!先谢谢了:)

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2011-07-25 22:11

浏览 2924

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值