Matlab R2009b引入了一个新的“运算符”-〜-表示未使用的函数输出或输入。我对此实施有详细的疑问。 (调用所有
@Loren 。)
对于未使用的输入参数的值,函数会看到什么?
即如果我的功能被定义为
myfunc(argOne, argTwo, argThree) 它这样称呼:
myfunc('arg', ~, 'arg') nargin是2还是3?是argTwo未定义还是为空或其他?
谢谢
回答:
~语法仅适用于函数
定义的输入,不适用于函数
调用的输入(如
本文档页面上所述 )。换句话说,
这是可以的:
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
更多&回答...