MATLAB: Is it possible to write a function with two different kind of output modes functionoutput How to write a function which can be used as y1 = myfunc(), or [y2,z] = myfunc(), but y1 will not be equal to y2! Best Answer Use nargout, something like this:function [X,Y] = myfun()if nargout==2 X = 1; Y = 2;else X = 0;endend Related SolutionsMATLAB: How to write a function with two kind of output modes Write the first line as:function [y,z] = myfunc()If you only request one output, only the first output is returned by default. MATLAB: Call to function with multiple outputs [~,y2] = f(x)https://www.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html Related QuestionHow to calculate curl of Laguerre-Gaussian modesHow to plot 2 surf plots in the same figureA function that outputs multiple plots
Best Answer