| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
function varargout = foo(n)
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.
The function
function [s,varargout] = mysize(x)
nout = max(nargout,1)-1;
s = size(x);
for k=1:nout, varargout(k) = {s(k)}; endreturns the size vector and, optionally, individual sizes. So
[s,rows,cols] = mysize(rand(4,5));
returns s = [4 5], rows = 4, cols = 5.
varargin, nargin, nargout, nargchk, nargoutchk, inputname
![]() | varargin | vectorize | ![]() |

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 |