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.