如何使用 matlabcontrol.jar 从 Java 调用用户定义的 Matlab
我正在尝试调用用户定义的 Matlab 函数(M 文件),该函数从我在 Eclipse 中开发的 Java 应用程序获取 3 个参数(Java 字符串)。目前,我可以使用 disp
或 sqr< 等函数/命令调用
proxy.eval
和 proxy.feval
方法/代码>。但是,当我尝试调用用户定义的函数时,它在 matlab 控制台上显示没有这样定义的函数,并且在 Java 控制台上发生 MatlabInitationException
。
然后我尝试使用一个简单的用户定义函数,该函数不带参数并且只有单行 disp('Hello')
但结果仍然相同。因此,我认为用户定义函数的调用方式存在问题,而不是类型转换问题。
请有人能尽快帮助我吗?我很快就会达到这个项目的最后期限。如果有人能提出解决方案,我将非常感激。 (Joshuwa Kaplan 先生,您的帖子中是否有解决此类问题的指南?我尝试过,但一无所获)
提前致谢
I am trying to call a user defined Matlab Function(M file) which takes 3 arguments(Java Strings) from my Java application which is developed in Eclipse. At the moment I am able to call proxy.eval
and proxy.feval
methods with the functions/commands like disp
or sqr
. But when i try to invoke a user-defined function it says on the matlab console that there is no such function defined like that and on the Java console MatlabInvocationException
occurs.
Then I tried with a simple user-defined function which takes no arguments and just has single line disp('Hello')
but still the result is same. So I think rather than a type conversion problem there is something wrong with how user-defined functions are getting invoked.
Please can anyone help me soon? I am meeting the deadline very soon for this project. I would be so thankful if someone can come up with a solution. (Mr Joshuwa Kaplan, is there any guide on solving an issue like this in your posts? I tried but found nothing)
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MATLAB 搜索路径上必须有任何用户定义的 m 文件,就像您在 MATLAB 中正常工作一样。
我使用以下示例进行了测试:
C:\some\path\myfunc.m
HelloWorld.java
我们编译并运行 Java 程序:
将打开一个 MATLAB 会话,并显示输出:
您还可以将文件夹添加到路径一次,然后使用 SAVEPATH 保存它。这样您就不必每次都这样做。
You must have any user-defined m-files on the MATLAB search path, just as if you were working normally inside MATLAB.
I tested with the following example:
C:\some\path\myfunc.m
HelloWorld.java
We compile and run the Java program:
a MATLAB session will open up, and display the output:
You could also add your folder to the path once, then persist it using SAVEPATH. That way you won't have to do it each time.