Inconsistent array notation in Java interface generated by MATLAB Compiler SDK?
3 views (last 30 days)
Show older comments
To call Matlab functions from Java, MATLAB's Compiler SDK generates functions with the following signatures.
/* mlx interface - List version*/
public void mysum(List lhs, List rhs)
throws MWException
/* mlx interface - Array version*/
public void mysum(Object[] lhs, Object[] rhs)
throws MWException
/* standard interface - no inputs */
public Object[] mysum(int nargout)
throws MWException
/* standard interface - variable inputs */
public Object[] mysum(int nargout, Object varargin)
throws MWException
Here, `mlx` seems to refer to an signature convention, and speculatively, the reasons for the name seem to be no longer relevant in the current context.
Here is an example invocation from within function getsum:
public double getsum(double[] vals) throws MWException
{
myclass cls = null; // Class containing the generated functions
Object[] x = {vals};
Object[] y = null;
try
{
cls = new myclass();
y = cls.mysum(1, x);
...snip...
"[O]bject array [x] of length 1 is created and initialized with a reference to the supplied double array. This argument is passed to the mysum method. The result is known to be a scalar double..." The invocation matches 4th and last signature above.
Why is argument x of type Object array (Object[] x) when the 4th signature shows a scalar Object (Object varargin)?
I realize that an array itself (i.e., Object[] x) is also an Object, but if that is how the prototypes are to be interpretted, then why is the array nature of the arguments explicit in the 2nd prototype above (Object[] rhs) but not the 4th prototype (Object varargin)?
0 Comments
Accepted Answer
Todd Flanagan
on 29 Oct 2020
You are correct that mlx is a convention. It refers to a c style interface that is familiar to people using other c-style MATLAB interfaces.
I don't know the specifics of why the particular signature was chosen and what the design trade offs were, but the signature does expect and Object [] array to be passed in as Object per the documentation.
In all cases, the varargin argument is passed as type Object. This lets you provide any number of inputs in the form of an array of Object, that is Object[], and the contents of this array are passed to the compiled MATLAB function in the order in which they appear in the array.
6 Comments
More Answers (0)
See Also
Categories
Find more on Call Java from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!