Actually, Mikhail's answer is not quite right. In the case that someFunction is a function that returns a value even if none is requested, which is how a function indicates that the value should be assigned to ans, Mikhail's wrapper will fail. For example, if someFunction were replaced with sin and you compared running wrapper versus running sin directly, you'd see:
>> wrapper(0)
>> sin(0)
ans =
0
The right way to do this is
function varargout = wrapper( varargin )
[varargout{1:nargout}] = someFunction( varargin{:} );
The reason this works is due to a little known edge case in MATLAB indexing rules that has existed precisely for this case since at least R2006a (probably longer). It is something of a wart in MATLAB indexing but was deemed necessary to handle this sort of thing.
The rule is:
When performing subscripted assignment, if
- subscripted-assigning to an uninitialized variable, AND
- the uninitialized variable is curly-brace indexed, AND
- the index in the curly braces is empty, AND
- the left-hand side appears inside square braces, AND
- the right-hand side resolves to a value / returns an output
Then the uninitialized variable is assigned a scalar cell containing the value returned by the right-hand side.
For example:
>> clear uninit % just to make sure uninit is uninitialized
>> [uninit{[]}] = sin(0)
uninit =
[0]