代码之家  ›  专栏  ›  技术社区  ›  Marc

Matlab未使用的输入符号详细信息

  •  3
  • Marc  · 技术社区  · 16 年前

    Matlab R2009b introduced a new "operator" -~-表示未使用的函数输出或输入。我对这个实施有详细的问题。(呼叫所有) @Loren 美国)

    对于未使用的输入参数的值,函数看到了什么?

    即,如果我的功能定义为

    myfunc(argOne, argTwo, argThree)
    

    它的名字是这样的:

    myfunc('arg', ~, 'arg')
    

    纳金2号还是3号? arg2是否未定义或为空或其他?

    谢谢

    1 回复  |  直到 14 年前
        1
  •  4
  •   gnovice    16 年前

    这个 ~ 语法只适用于函数的输入 定义 ,而不是函数的输入 呼叫 (如前所述 this documentation page )换句话说, 这 可以:

    function myfunc(argOne, ~, argThree)  %# Will do nothing with the second input
      %# Do stuff here
    end
    

    但是 这 不是:

    myfunc('arg', ~, 'arg');  %# Error city ;)
    

    因此,在调用函数时,只能使用 ~ 上 左侧 :

    [~, I] = sort([2 4 1 2 5 3]);  %# Sort the vector and keep only the index