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