Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

varargout - Variable length output argument list

Syntax

function varargout = foo(n)

Description

function varargout = foo(n) returns a variable number of arguments from function foo.m.

The varargout statement is used only inside a function M-file to contain the optional output arguments returned by the function. The varargout argument must be declared as the last output argument to a function, collecting all the outputs from that point onwards. In the declaration, varargout must be lowercase.

Examples

The function

function [s,varargout] = mysize(x)
nout = max(nargout,1)-1;
s = size(x);
for k=1:nout, varargout(k) = {s(k)}; end

returns the size vector and, optionally, individual sizes. So

[s,rows,cols] = mysize(rand(4,5));

returns s = [4 5], rows = 4, cols = 5.

See Also

varargin, nargin, nargout, nargchk, nargoutchk, inputname

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS