How to check if output argument is ignored?

5 ビュー (過去 30 日間)
Jos (10584)
Jos (10584) 2018 年 1 月 30 日
コメント済み: Ulf Ranggård 2022 年 4 月 6 日
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

採用された回答

Stephen23
Stephen23 2018 年 1 月 30 日
編集済み: Stephen23 2018 年 1 月 30 日
  4 件のコメント
Jos (10584)
Jos (10584) 2018 年 1 月 30 日
Done!
Adding an input to nargout would do: nargout(N) returning true if the N-th output argument is present and not ignored ... Without input argument, no change in behaviour. Plain and simple, without functionality loss, I think :D
Ulf Ranggård
Ulf Ranggård 2022 年 4 月 6 日
It's now 2022, apparently this suggestion was not implemented?
Are there now any other standard way to detect the callers use of ~ ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by