从Java运行MATLAB函数 [英] Running MATLAB function from Java
问题描述
我在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都会打开一个单独的窗口,这是一个问题因为我' d喜欢多次运行。
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 基于Jeff提到的MatlabControl所使用的相同底层MATLAB库,但它更新,更可靠,更具记录性。要开始使用,请查看演练。
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屋!