%% Variable Number of Function Outputs
% Define a function in a file named returnVariableNumOutputs.m that returns an output size vector s and a variable number of additional outputs.

type returnVariableNumOutputs

% Output s contains the dimensions of the input array x. Additional outputs correspond to the individual dimensions within s.
% Call the function with a three-dimensional array and request three outputs.

A = rand(4,5,2);
[s,rows,cols] = returnVariableNumOutputs(A)

% Call the function again with a four-dimensional array and request four outputs. This time, the function does not return the individual fourth dimension.

A = zeros(1,4,5,2);
[s,dim1,dim2,dim3] = returnVariableNumOutputs(A)

% Call the function once more on A and request one output. Now the function returns the dimensions of A and not varargout.

s = returnVariableNumOutputs(A)

% Copyright 2012 The MathWorks, Inc.