MATLAB ActiveX 可选参数

3

有一个ActiveX函数,我想从MATLAB中调用,例如:

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

然后像下面这样使用:

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

PrintOut函数调用中的所有参数都是可选参数。然而,在某些情况下,我需要指定第3、9和10个参数,并将其他所有参数保留为默认值。在通过MATLAB调用的ActiveX函数调用中,有没有可能指定缺失或默认值?在C#中可以这样做,但在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);

致敬,

2个回答

3
根据Matlab文档,您可以通过使用空数组(即[])来跳过可选的输入参数
因此,代码看起来像这样:
hdlActiveX.PrintOut([],needed args,[],needed args);

会和默认值一样吗?...我会尝试一下。谢谢。 - HeinrichStack

0

我在默认/可选参数中使用NaN,这对我很有效。所以我的版本是:

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

老实说,我认为两者都可以很好地工作。希望这可以帮助你!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接