从 Java 运行 MATLAB 函数 [英] Running MATLAB function from Java

查看:37
本文介绍了从 Java 运行 MATLAB 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MATLAB 中有一个 .m 文件,我想从 Java 调用它并以字符串或 Java 中的任何形式获取解决方案.这听起来很简单,但由于某种原因我无法让它工作.

I have an .m file in MATLAB which I would like to call from Java an get the solution as a string or whatever in Java. This sounds really simple but for some reason I can't make it work.

我试过了:

matlab -nosplash -wait -nodesktop -r  myFunction

但我不确定如何解析答案,因为 MATLAB 打开它自己的命令行(在 Windows 中).

but I'm not sure how I parse the answer since MATLAB opens it's own command line (in Windows).

我使用它,但它没有返回任何东西.

I use this, but it doesn't return anything.

Process p = Runtime.getRuntime().exec(commandToRun);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

而且似乎每次我调用 MATLAB 时它都会打开一个单独的窗口,这是一个问题,因为我想多次运行.

also it seems that every time I call MATLAB it opens a separate window which is a problem because I'd like to run this many times.

推荐答案

matlabcontrol 基于相同的底层 MATLABJeff 提到的 MatlabControl 使用的库,但更新、可靠和记录.首先,请查看演练.

matlabcontrol is based on the same underlying MATLAB library used by MatlabControl mentioned by Jeff, but is more up to date, reliable, and documented. To get started, take a look at the walkthrough.

这篇关于从 Java 运行 MATLAB 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆