Suppose I have a heavy-duty workhorse of a function:
[a b c d] = lotsOfComputation();
In some use cases, I may only need one or two of its outputs. In those cases, I ignore the output with a ~. Is it possible to detect this from within the lostOfComputation function?
(Yes, I know the more elegant solution is a refactor into separate functions. I have already done this for the immediate use-case, but the question remained in my head.)
Sure, try nargout, it returns the number of output arguments. Well, actually that will work when the argument is omitted, but it will count ~ as an argument. Here’s an example:
So perhaps the answer to your exact question is no, at least not with
nargout.