This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Variable-length output argument list




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.


collapse 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);

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 =

cols =

Introduced before R2006a

Was this topic helpful?