MATLAB: How to write a function with two kind of output modes functionoutput How to write a function which can be used as y = myfunc(), or [y,z] = myfunc() ? Best Answer Write the first line as:function [y,z] = myfunc()If you only request one output, only the first output is returned by default. Related SolutionsMATLAB: Is it possible to write a function with two different kind of output modes Use nargout, something like this:function [X,Y] = myfun()if nargout==2 X = 1; Y = 2;else X = 0;endend MATLAB: How to make function that sometimes return output and how to call Simplest solution: set a default output value:function [a,b] = myfn(x,y)a = 1;b = [];if(x=y) b = 2;endend Related QuestionHow to calculate curl of Laguerre-Gaussian modesMatlab function outputs save in structureHow can one write a program to do this? (fminbnd)Cell ModeHow to use multiple outputs from function
Best Answer