User`s guide

R2009b
15-18
Programming
Ignore Selected Arguments on Function Calls
This version of MATLAB introduces a new usage for the tilde (~) operator. As in
earlier releases, tilde signifies a logical NOT. In the 9b release, you can also use
the tilde operator to specify unused outputs in a function call, or unused inputs in a
function definition. See Ignore Function Inputs in the Programming Fundamentals
documentation for more information on this feature.
Replacing Output Variables with Tilde
This feature enables you to replace this type of function call:
[val1, ignoreThisOutput, val3] = myTestFun;
with the following:
[val1, ~, val3] = myTestFun;
MATLAB ignores any values returned by a function that have a corresponding tilde in
the output list. This new syntax can help you avoid confusion in your program code and
unnecessary clutter in your workspace. It also avoids wasting memory to store unused
outputs returned from the called function.
Replacing Input Arguments with Tilde
You can also use the tilde operator to specify unused inputs when you are creating a
function. You can replace this type of function definition:
function myTestFun(arg1, ignoreThisInput, arg3)
with the following
function myTestFun(arg1, ~, arg)
Whenever this function is called, MATLAB ignores any inputs passed to the function that
have a tilde in the corresponding position in the input argument list. You are likely to
find the tilde operator most useful when writing callback functions and subclass methods
that must match a predefined function interface.