title: calling a function in matlab and letting the caller determine the number of output arguments at runtime
body: <p>Is there a way to generalize the following? (<strong>note: <code>nargout_requested</code> may not be known except at runtime</strong>)</p>
  
  <pre><code>function outputs = apply_and_gather(f, args, nargout_requested)
    switch nargout_requested
      case 0
        f(args{:});
        outputs = {};
      case 1
        o1 = f(args{:});
        outputs = {o1};
      case 2
        [o1,o2] = f(args{:});
        outputs = {o1,o2};
      case 3
        [o1,o2,o3] = f(args{:});
        outputs = {o1,o2,o3};
        ...
  </code></pre>
  
  <p>In other words, I want to call a function with a cell array of arguments, and assign the function's outputs to a cell array, and request a certain # of output arguments.</p>
  
  <p>In python this would just be:</p>
  
  <pre><code>outputs = f(*args)
  </code></pre>
  
  <p>but Matlab requires you to tell a function how many arguments you want before you call it, and gives you an error if you have too many output arguments.</p>