This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Ignore Function Inputs

This example shows how to ignore inputs in your function definition using the tilde (~) operator.

Use this operator when your function must accept a predefined set of inputs, but your function does not use all of the inputs. Common applications include defining callback functions, as shown here, or deriving a class from a superclass.

Define a callback for a push button in a file named colorButton.m that does not use the eventdata input. Ignore the input with a tilde.

function colorButton
uicontrol('Style','pushbutton','String','Click me','Callback',@btnCallback)

function btnCallback(h,~)

The function declaration for btnCallback is essentially the same as

function btnCallback(h,eventdata)

However, using the tilde prevents the addition of eventdata to the function workspace and makes it clearer that the function does not use eventdata.

You can ignore any number of function inputs, in any position in the argument list. Separate consecutive tildes with a comma, such as