Comments on: Managing code in MATLAB: Functions of variable numbers of inputs and outputs https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/?s_tid=feedtopost Stuart uses video to share his experiences solving problems with MATLAB day-to-day, interesting new features, plus tips and tricks he has picked up along the way. Tue, 29 May 2012 18:43:40 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Doug https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3089 Tue, 29 May 2012 18:43:40 +0000 https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3089 Peter,

I think you are referring to this case:

function varargout = main(varargin)

varargout{1} = nargout;
varargout{2} = nargin;

——-

>>main

ans =

0

————–

Within the context of the function itself, it sees that there were no *requested* outputs. That is indeed correct within that context.

From the outside, if there are no *requested* outputs the variable ans will be the assumed left hand variable to be assigned the default one output case.

What would you expect to happen here? Self-referential statements can lead to paradoxes: “This statement is false.”

-Doug

]]>
By: Doug https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3088 Tue, 29 May 2012 18:43:34 +0000 https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3088 Peter,

I think you are referring to this case:

function varargout = main(varargin)

varargout{1} = nargout;
varargout{2} = nargin;

——-

>>main

ans =

0

————–

Within the context of the function itself, it sees that there were no *requested* outputs. That is indeed correct within that context.

From the outside, if there are no *requested* outputs the variable ans will be the assumed left hand variable to be assigned the default one output case.

What would you expect to happen here? Self-referential stements can lead to paradoxes: “This statement is false.”

-Doug

]]>
By: Doug https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3087 Tue, 29 May 2012 18:43:14 +0000 https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3087 Peter,

I think you are referring to this case:

function varargout = main(varargin)

varargout{1} = nargout;
varargout{2} = nargin;

——-

>>main

ans =

0

————–

Within the context of the function itself, it sees that there were no *requested* outputs. That is indeed correct within that context.

From the outside, if there are no *requested* outputs the variable ans will be the assumed left hand variable to be assigned the default one output case.

What would you expect to happen here? Self-referential logical can lead to paradoxes: “This statement is false.”

-Doug

]]>
By: Peter https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3070 Fri, 11 May 2012 21:53:04 +0000 https://blogs.mathworks.com/videos/2011/07/20/starting-in-matlab-functions-of-variable-numbers-of-inputs-and-outputs/#comment-3070 You didn’t show the fun case where you type “main()” and it prints “0” because you requested no outputs. Explain how that makes any sense. How does it produce an output 0 if it didn’t have any outputs to produce?

]]>