Ignoring function outputs¶
This example shows how to disregard some function output by using the tilde (~) operator.
Suppose we have some data array. We need to find the element with the minimum value and its index.
A = rand(5,5)
To find the element with the minimum value and its index, there is a function findmin()
.
(min, idx) = findmin(A)
Now there are two variables in the workspace. In this case, the variables are small. However, some functions return results that consume much more memory. Therefore, to ignore the output of a function, use the tilde operator at any position in the argument list. In our example, only the index of the minimum value can be output.
(~, idx) = findmin(A)
You can ignore any number of function outputs by using the tilde operator. You can also output the first N output data of the function and ignore all other output data. In our case, we can get the minimum value of the function without an index. Thus, only one variable will be created.
minA = findmin(A)
Conclusion¶
In this article we have learnt how to reduce the output of variables in some functions using the tilde operator (~).