MEX and Matlab - Check if an output is skipped/unused, i.e. marked with tilde (~)
9 views (last 30 days)
Show older comments
Hi,
Is there a way in the MEX API to check whether an output was skipped, i.e. marked with a tilde (~)? Specifically, suppose I do:
[~,y]=myfunc(x);
In MEX, nlhs is set to 2. Is there a way to determine that plhs[0] is unwanted?
How about in Matlab .m code? I could then write a wrapper accordingly for the myfunc mex file (not ideal, but would work).
Cheers, Alex.
p.s. I have already seen this (and am aware I could write separate functions, but it would be infinitely better to detect the tilde)
1 Comment
Bernt Nilsson
on 13 Jun 2018
I have the same problem, and three years have passed. Is it yet possible to detect the tilde?
Answers (1)
Jan
on 7 Feb 2015
Edited: Jan
on 7 Feb 2015
There is no way, as far as I know neither officially nor undocumented.
Instead of coding the unwanted outputs by the tilde, using a clear and clean input argument is better in my opinion. It is much better to see the intention of the programmer eplicitly than a smart and fancy way to hide this inside intelligent parsing.
If you see a foreign code, or a code written by your own some years ago, decide what is nicer:
opt.OutputX_wanted = false;
y = myfunc(x, opt);
or
[~, y] = myfunc(x)
In the first case you can imagine, that myfunc can save some time, in the second this is not expected by experienced Matlab programmers. Although if the 2nd method might save some lines of code or some microseconds of run time, the debug time rules.
2 Comments
Jan
on 8 Feb 2015
I agree, that the ~ method is not really usful. Therefore programmers have to use more efficient ways.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!