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 Outputs

This example shows how to request specific outputs from a function.

Request all three possible outputs from the fileparts function.

helpFile = which('help');
[helpPath,name,ext] = fileparts(helpFile);

The current workspace now contains three variables from fileparts: helpPath, name, and ext. In this case, the variables are small. However, some functions return results that use much more memory. If you do not need those variables, they waste space on your system.

Request only the first output, ignoring the second and third.

helpPath = fileparts(helpFile);

For any function, you can request only the first N outputs (where N is less than or equal to the number of possible outputs) and ignore any remaining outputs. If you request more than one output, enclose the variable names in square brackets, [].

Ignore the first output using a tilde (~).

[~,name,ext] = fileparts(helpFile);

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

[~,~,ext] = fileparts(helpFile);