【问题标题】:MATLAB ActiveX optional argumentsMATLAB ActiveX 可选参数
【发布时间】:2012-01-12 13:47:04
【问题描述】:

有一个 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);

问候,

【问题讨论】:

    标签: matlab activex optional-parameters


    【解决方案1】:

    根据 Matlab 文档,您可以使用空数组(即[])来跳过optional input arguments。

    所以这看起来像:

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

    【讨论】:

    • 会和默认值一样吗? ... 我会试试。谢谢。
    【解决方案2】:

    我使用 NaN 作为默认/可选参数,它适用于我。所以我的版本是:

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

    老实说,我认为两者都可以正常工作。希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 2018-04-14
      相关资源
      最近更新 更多