Calling matlab callback/function handle from Java

☆樱花仙子☆ 提交于 2019-12-04 05:39:51

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.

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

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.

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

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!