How to check if output argument is ignored?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jos (10584)
el 30 de En. de 2018
Comentada: Ulf Ranggård
el 6 de Abr. de 2022
Is is possible to check if a function gets called with to-be-ignored output arguments (using ~)?
function [Y1, Y2] = MyFunction(...)
% common code for Y1 and Y2 here
if //insert_check_here//
% avoid this code when called as [~, B] = MyFunction (...)
end
For all these situations below, however, nargout returns 2, so that function seems to have no use in solving my problem.
[~,b] = myFunction
[a,~] = myFunction
[~,~] = myFunction % you may think about the usefulness of this call :)
Thanks! ~ Jos
0 comentarios
Respuesta aceptada
Stephen23
el 30 de En. de 2018
Editada: Stephen23
el 30 de En. de 2018
No, it is currently not possible without writing some hack with dbstack and parsing the calling file. See also:
4 comentarios
Ulf Ranggård
el 6 de Abr. de 2022
It's now 2022, apparently this suggestion was not implemented?
Are there now any other standard way to detect the callers use of ~ ?
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!