varargout
Specifies that a function can return a variable number of outputs.
Syntax
function varargout = foo()
end
Outputs
- varargout
- Anything that can be an output of a function.
Examples
Simple output example:
function varargout = foo()
varargout{1} = 10;
varargout{2} = 20;
varargout{3} = 30;
end
[a] = foo()
a = 10
function varargout = foo()
varargout{1} = 'a';
varargout{2} = 'b';
varargout{3} = 'c';
end
foo() % it should return the first element of varargout here
R = foo() % it should return the first element of varargout here
[R1, R2] = foo() % it returns 'a' in R1 and 'b' in R2 OK
[R1,R2, R3] = foo() % it returns 'a' in R1 and 'b' in R2 OK and 'c' in R3 OK
ans = a
R = a
R1 = a
R2 = b
R1 = a
R2 = b
R3 = c