Documentation Center

  • Trial Software
  • Product Updates

varargout

Variable-length output argument list

Syntax

varargout

Description

varargout is an output variable in a function definition statement that allows the function to return any number of output arguments. Specify varargout using lowercase characters, and include it as the last output argument after any explicitly declared outputs. When the function executes, varargout is a 1-by-N cell array, where N is the number of outputs requested after the explicitly declared outputs.

Examples

expand all

Variable Number of Function Outputs

Define a function in a file named sizeout.m that returns an output size vector s and a variable number of additional scalar values.

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

Output s contains the dimensions of the input array x. Additional outputs correspond to the individual dimensions within s.

Call sizeout on a three-dimensional array and request three outputs.

[s,rows,cols] = sizeout(rand(4,5,2))
s =
     4     5     2

rows =
     4

cols =
     5

See Also

| | | | |

Was this topic helpful?