![]() |
Matlab未使用的输入符号详细信息
[URL="http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/"]Matlab R2009b引入了一个新的“运算符”-〜-[/URL]表示未使用的函数输出或输入。我对此实施有详细的疑问。 (调用所有[URL="https://stackoverflow.com/users/113700/loren"]@Loren[/URL] 。)
对于未使用的输入参数的值,函数会看到什么? 即如果我的功能被定义为 myfunc(argOne, argTwo, argThree) 它这样称呼: myfunc('arg', ~, 'arg') nargin是2还是3?是argTwo未定义还是为空或其他? 谢谢 [B]回答:[/B] ~语法仅适用于函数[I]定义[/I]的输入,不适用于函数[I]调用[/I]的输入(如[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#br67dkp-1"]本文档页面上所述[/URL] )。换句话说, [I]这[/I]是可以的: function myfunc(argOne, ~, argThree) %# Will do nothing with the second input %# Do stuff here end [I]但这[/I]不是: myfunc('arg', ~, 'arg'); %# Error city ;) 因此,在调用函数时,只能在[I]左侧[/I]使用~ : [~, I] = sort([2 4 1 2 5 3]); %# Sort the vector and keep only the index [url=https://stackoverflow.com/questions/2002542]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 21:19。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.