With an anonymous function, you can return any number of outputs. What I need is to be able to use functors (anonymous functions as arguments of other functions), while not knowing how many outputs I will get.
This is to avoid code duplication by injecting functions calls inside a while loop which is reused in many functions.
Example:
function y = foo( x )
y = x;
end
function [y1, y2] = goo( x1, x2 )
y1 = x1;
y2 = x2;
end
function [ varargout ] = yolo( functor, varargin )
varargout = functor(varargin{:});
end
I want to be able to call:
y = yolo(@foo, 2)
[y1, y2] = yolo(@goo, 3, 4);
Is there any way to achieve this ? Thanks