help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling variable number of output arguments in multi-level function


From: Jose
Subject: Re: Handling variable number of output arguments in multi-level function calls
Date: Fri, 12 Dec 2014 15:40:57 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 12/12/14 14:41, Juan Pablo Carbajal wrote:
If you use varargout in your f1 function, then you could do

OUT = nthargout (1:nargout, @f2, varargin{:});

and then distribute the cell OUT in the outputs of f1. I think you
will have to have a special check for the case nargout=1.

That is a possibility as well, thanks. For completeness:
--->
function [o1,o2]=f1(varargin)
  o1=1;
  o2=2;
endfunction

function varargout=f2(varargin)
  if nargout==0, varargout{1}=f1(varargin{:}); return; endif
  OUT=nthargout (1:nargout, @f1, varargin{:});
  if nargout==1,
    varargout{1}=OUT;
  else
    varargout= OUT;
  endif
endfunction
<---
Using this we have
--->
octave:3> f2
ans =  1
octave:4> a=f2
a =  1
octave:5> [a,b]=f2
a =  1
b =  2
<---


J.



_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave





reply via email to

[Prev in Thread] Current Thread [Next in Thread]