How can I detect inside a function which output args are being used by the caller ie. those that aren't "~"?
3 ビュー (過去 30 日間)
古いコメントを表示
I have a function which is called multiple times with different inputs. I don't always require all the outputs and it takes effort to provide each output, so it'd be nice to skip some of the processing for those not being used. I know about nargout, but that's only efficient if your outputs are hierarchical
eg. I want to expend the minimum amount of effort to calc a,b and c in all of these examples [a,b,c] = func(); [~,~,c] = func(); [a,~,c] = func(); [~,b] = func();
0 件のコメント
回答 (1 件)
Niklas Nylén
2014 年 4 月 17 日
Unless this has been added very recently there is unfortunately no way to know which outputs will actually be used. One way to achieve the same result would be to add flags to the input data and use those to select which calculations to perform.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!