-->

MATLAB ActiveX optional arguments

2020-04-11 06:42发布

问题:

there is an ActiveX function, which I want to call from MATLAB, e.g.

PrintOut([Background], [Append], [Range], [OutputFileName], [From], [To], [Item], [Copies],
 [Pages], [PageType], [PrintToFile], [Collate], [FileName], [ActivePrinterMacGX],
 [ManualDuplexPrint], [PrintZoomColumn], [PrintZoomRow], [PrintZoomPaperWidth],
 [PrintZoomPaperHeight])

and use it like follows :

hdlActiveX = actxserver('Word.Application');
hdlActiveX.PrintOut(opt args, needed args, opt opts, needed args);

All arguments in the PrintOut function call are optional arguments. However, for a particular case, I need to specify argument #3,#9,#10 and to leave all other to default. Is there a possibility to specify missing or default values in an ActiveX function call invoked via MATLAB ?!?

In C# this could be done like this, but in Matlab ActiveX ... ?!?

this.PrintOut(ref Background, ref missing, ref Range, ref missing,
    ref missing, ref missing, ref missing, ref Copies,
    ref missing, ref PageType, ref PrintToFile, ref Collate,
    ref missing, ref ManualDuplexPrint, ref PrintZoomColumn,
    ref PrintZoomRow, ref missing, ref missing);

Regards,

回答1:

According to the Matlab documentation, you can skip optional input arguments by using an empty array instead (i.e. []).

So this would looks like:

hdlActiveX.PrintOut([],needed args,[],needed args);


回答2:

I use NaN for default/optional parameters and it works for me. So my version would be:

hdlActiveX.PrintOut(NaN, needed args, NaN, needed args);

Honestly, I think both would work fine. Hope this helps!