MATLAB: Does ACTXSERVER not recognize an optional argument with a default value in MATLAB

activexactxservercomcomponentdefaultinterfacelimitationMATLABoptional

I define an ActiveX component with optional arguments and default values:
Public Function MyMethod(X As Double, Y As Double, _
Optional A As Long = -1, Optional B As Long = -1) As Variant
When I invoke it, specifying the default arguments:
f = actxserver('MyProj.MyComp');
f.invoke('MyMethod', 1, 2, 3, 4)
I receive the error message:
??? No method 'MyMethod' with matching signature found for class 'COM.MyProj_MyComp'.

Best Answer

This is a result of a limitation in the way MATLAB interfaces with ActiveX components.
To work around this limitation, do one of the following:
1. Invoke the method using the lower-case version of its name:
f.invoke('mymethod', 1, 2, 3, 4)
(or at least a lower-case first letter).
2. Do not specifiy the default values for arguments in the ActiveX component:
Public Function MyMethod(X As Double, Y As Double, _
Optional A As Long, Optional B As Long) As Variant
3. Call the method without specifying the optional arguments:
f.invoke('MyMethod', 1, 2)