MATLAB Function Reference Previous page   Next Page
varargin, varargout

Return variable number of arguments

Syntax

Description

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

function y = bar(varargin) accepts a variable number of arguments into function bar.m.

The varargin and varargout statements are used only inside a function M-file to contain the optional arguments to the function. Each must be declared as the last argument to a function, collecting all the inputs or outputs from that point onwards. In the declaration, varargin and varargout must be lowercase.

Examples

The function

collects all the inputs starting with the second input into the variable varargin. myplot uses the comma-separated list syntax varargin{:} to pass the optional parameters to plot. The call

results in varargin being a 1-by-4 cell array containing the values 'color', [.5 .7 .3], 'linestyle', and ':'.

The function

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

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

See Also

nargin, nargout, nargchk, nargoutchk, inputname


Previous page  var vectorize Next page

© 1994-2005 The MathWorks, Inc.