Is it possible to write a function with two different kind of output modes?

조회 수: 1 (최근 30일)
How to write a function which can be used as y1 = myfunc(), or [y2,z] = myfunc(), but y1 will not be equal to y2!

채택된 답변

Stephen23
Stephen23 2017년 7월 17일
편집: Stephen23 2017년 7월 17일
Use nargout, something like this:
function [X,Y] = myfun()
if nargout==2
X = 1;
Y = 2;
else
X = 0;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by