How to avoid ambiguity when calling Java from Matlab?

烈酒焚心 提交于 2019-12-06 04:37:44

You may be running into some problems with how MATLAB does dispatching...

How do I know which method will be called given the same name?

This section of the MATLAB documentation discusses how a function is chosen in cases when there are multiple functions with the same name. From the documentation: "The function precedence order determines the precedence of one function over another based on the type of function and its location on the MATLAB path." This order (from highest to lowest) is given below:

  • Subfunction
  • Private function
  • Class constructor
  • Overloaded method
  • Function in current directory
  • Function elsewhere on the path

The placement of your "method.m" function will likely determine if it gets called or the Java method gets called when using the "method(object,...)" syntax.

Is there a way to ensure I call method.m instead of the Java method?

Right now, I'm guessing your "method.m" is in the current directory or elsewhere on the path (the two lowest precedence positions to be in). If you made "method.m" a subfunction in the larger code calling it, or if it's possible to put it in a private directory where it can be called by every function that needs to call it, then it may get called instead of the Java method when you use the "method(object,...)" syntax.

Hope this helps!

Hmmmmmmmmm.... you could try obtaining a function handle using @method and then call feval() on the function handle.

That might work but I'm not sure....

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