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

1 visualizzazione (ultimi 30 giorni)
How to write a function which can be used as y1 = myfunc(), or [y2,z] = myfunc(), but y1 will not be equal to y2!

Risposta accettata

Stephen23
Stephen23 il 17 Lug 2017
Modificato: Stephen23 il 17 Lug 2017
Use nargout, something like this:
function [X,Y] = myfun()
if nargout==2
X = 1;
Y = 2;
else
X = 0;
end
end

Più risposte (0)

Categorie

Scopri di più su Argument Definitions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by