从 Java 调用 matlab 回调/函数句柄

发布于 2024-07-24 10:30:00 字数 242 浏览 8 评论 0原文

如何将 matlab 函数句柄传递给 Java 对象并从 Java 内部调用它(也就是说,我希望 Java 告诉 matlab 何时准备好进行计算)。 我正在尝试使用 com.mathworks.jmi.Matlab 类来评估 Java 对象中的 Matlab 表达式,但我看不到如何 1) 将回调函数句柄传输到 Java,以及 2) 从 Java 调用它(可能使用) com.mathworks.jmi.Matlab 类。

谢谢, 雅各布

How do I pass a matlab function handle to a Java object and invoke it from within Java (that is, I want Java to tell matlab when it is ready with a calculation). I am trying to use the com.mathworks.jmi.Matlab class for evaluating Matlab expressions in the Java object, but I can't see how to 1) transfer the callback funcktion handle to Java, and 2) invoke it from Java possibly using the com.mathworks.jmi.Matlab class.

Thanks,
jakob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

违心° 2024-07-31 10:30:00

唔。 看起来 JMI 是 matlab 内部的东西之一,在未来的版本中可能会发生变化。 我找到了这些在线文章,不确定它们是否对您的情况有帮助。

Hmm. Looks like JMI is one of those matlab internals things which may be subject to change in future versions. I found these online articles, not sure if they will help in your case.

坏尐絯℡ 2024-07-31 10:30:00

恐怕我不知道如何完全执行您所要求的操作,但是有两种方法可以执行类似的操作:

1)如果您从 Matlab 中设置 Java 回调,那么您 可以可以向它发送一个 Matlab 函数句柄。 当引发 Java 回调事件时,将调用您的 Matlab 函数。 可以在这里找到一个示例: http://UndocumentedMatlab.com/blog/uicontrol-callbacks/ 。 请注意,这不需要 JMI 来运行。

2)JMI需要一个字符串(函数名或命令行)供Matlab计算。 如果您事先知道函数名称,则可以使用它。 否则,您可以准备一个 Matlab switch-yard 函数(其名称预先已知)来动态地将您的回调定向到适当的 Matlab 操作。

我计划四月中旬在 http://UndocumentedMatlab.com 网站上发表一篇关于 JMI 的文章,敬请关注...

亚尔奥特曼

I'm afraid that I do not know of a way to do exactly what you requested, but there are two ways you can do something similar:

1) If you set a Java callback from within Matlab, you can send it a Matlab function handle. When the Java callback event gets raised, your Matlab function will be invoked. An example for this can be found here: http://UndocumentedMatlab.com/blog/uicontrol-callbacks/. Note that this does not need JMI to run.

2) JMI needs a string (function name or command line) for Matlab to evaluate. If you know the function name in advance you can use it. Otherwise, you can prepare a Matlab switch-yard function (whose name is known in advance) to dynamically direct your callback to the appropriate Matlab action.

I plan to run an article about JMI in the http://UndocumentedMatlab.com website in mid-April, so stay tuned...

Yair Altman

初见你 2024-07-31 10:30:00

matlabcontrol 是一个 Java API,可让您执行此操作。 它可以使用 feval 调用 MATLAB 函数。 它不能直接在函数句柄上操作,但正如 KitsuneYMG 提到的,您可以使用 func2str 将函数句柄转换为字符串。 首先,您可以查看演练

matlabcontrol is a Java API which will allow you to do that. It can invoke a MATLAB function using feval. It cannot operate directly on a function handle, but as mentioned by KitsuneYMG, you can use func2str to convert a function handle to a string. To get started, you can take a look at the walkthrough.

眉目亦如画i 2024-07-31 10:30:00

要将回调传递给 matlab,请将 matlab 函数的名称及其参数传递给 com.mathworks.jmi.Matlab.feval("matlabControlcb", ... , 0);
... 是一个 Object[],其中 [0] = 命令,[1..end]= 参数。

另请参阅:FEVAL FUNC2STR

To pass a callback into matlab, you pass the name of the matlab function and it's arguments into com.mathworks.jmi.Matlab.feval("matlabControlcb", ... , 0);
The ... is an Object[] where [0] = command and [1..end]=arguments.

See Also: FEVAL FUNC2STR

停顿的约定 2024-07-31 10:30:00

试试这个工具: http://jamal.sourceforge.net/

它完全可以满足您的需求,而且效果很好-记录在案。

它所基于的主要原理是对Matlab内部运行的服务器部分进行RMI调用。 输出返回到java程序。 再说一遍,这取决于jmi...

try this tool: http://jamal.sourceforge.net/

It does exactly what you need and well-documented.

The main principle it is based on is to make RMI call to the server part that is run inside Matlab. The output is returned to java program. Again, it depends on jmi...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文