Why doesn't evalin('caller','nargout') work?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt J
am 1 Dez. 2022
Kommentiert: Bruno Luong
am 1 Dez. 2022
Why doesn't the mynargout() function correctly return n=3? How can one programmatically evaluate nargout in the calling function?
[A,B,C]=Func();
function varargout=Func
varargout={1,2,3};
nargout
mynargout
end
function n=mynargout()
n=evalin('caller','nargout');
end
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 1 Dez. 2022
Bearbeitet: Bruno Luong
am 1 Dez. 2022
Obviously it is NOT a normal "function", according to the doc of nargout
"nargout returns the number of function output arguments specified in the call to the currently executing function. Use this syntax in the body of a function only."
Therfore the nargout won't be propagae by evalin but returns the result corresponds number of the output to the last function in the stack meaning mynargout
[A,B,C]=Func();
function varargout=Func
varargout={1,2,3};
a=nargout
b=mynargout
end
function n=mynargout()
n=evalin('caller','nargout');
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Argument Definitions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!