Capture all possible outputs based on a variable number of inputs.

I would like Matlab to return all outputs from an input function variable. For instance,

[varargout] = cpd_intersect (varargin {:});

This only returns the last output, but I know that the function is defined to receive multiple outputs.

Instead of defining dummy variables A, B, C, etc. in [A, B, C ...] = pd_intersect (varargin {:}). I would like something like a cell to store all output values ​​based on the input number of values. I hope this makes sense. Thank you very much in advance.

+5
source share
3 answers

I know this is late, but I think this is what you want:

function [varargout] = myfun(f, varargin)
% apply f to args, and return all its outputs

[ x{1:nargout(f)} ] = f(varargin{:}); % capture all outputs into a cell array
varargout = x;                        % x{:} now contains the outputs of f

Insight here is that

  • NARGOUT
  • [ X{1:2} ] = ... , X undefined, [ X{1} X{2} ] = ... 2 .

:

  • ! @(x)eig(x)
  • , varargout, .. . , , , . nargin.

PS @gnovice, MATLAB , ?

+5

,

0

I see that you cannot force a variable dividing list in Matlab. A pity. That would be helpful. It seems I should explicitly assign each conclusion. This sucks because I don’t know in advance how many results I will get.

0
source

All Articles