# Forcing Variable Outputs

5 messages
Open this post in threaded view
|

## Forcing Variable Outputs

 I have a function that I want to force to have a variable number of output arguements based on its calling function's number of output arguements. In other words, I want to do something like function [varargout] = fxn1(varargin)    varargout{:} = fxn2(varargin{:}); endfunction and I want fxn2 to see the same number of output arguements that fxn1 sees. I thought of initializing varargout like varargout = cell(1, nargout); but that didn't work.  Is there a way to do this? Bill -- From Dumblaws.com:  In China, to go to college you must be intelligent. ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web:  http://www.octave.orgHow to fund new projects:  http://www.octave.org/funding.htmlSubscription information:  http://www.octave.org/archive.html-------------------------------------------------------------
Open this post in threaded view
|

## Re: Forcing Variable Outputs

 Does this do what you want?   function varargout = fxn1 (varargin)     varargout = fxn2 (varargin{:});   endfunction   function varargout = fxn2 (varargin)     varargout = {varargin};   endfunction I see: octave2.9:1> a = fxn1 (1) a = 1 octave2.9:2> [a, b] = fxn1 (1, 2) a = 1 b = 2 On Tue, 2006-03-28 at 20:53 -0500, Bill Denney wrote: > I have a function that I want to force to have a variable number of output > arguements based on its calling function's number of output arguements. > In other words, I want to do something like > > function [varargout] = fxn1(varargin) > >    varargout{:} = fxn2(varargin{:}); > > endfunction > > and I want fxn2 to see the same number of output arguements that fxn1 > sees. > > I thought of initializing varargout like > > varargout = cell(1, nargout); > > but that didn't work.  Is there a way to do this? > > Bill > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web:  http://www.octave.orgHow to fund new projects:  http://www.octave.org/funding.htmlSubscription information:  http://www.octave.org/archive.html-------------------------------------------------------------
Open this post in threaded view
|

## Re: Forcing Variable Outputs

 Not exactly.  As I tried that, it just gave the output as the same as the input.  The problem is that I want this to work correctly (without having to do a lot of if blocks). function [varargout] = fxn1(varargin)    nargin    nargout    varargout{:} = fxn2(varargin{:}); endfunction function [varargout] = fxn2(varargin)    nargin    nargout    varargout = {varargin}; endfunction As it is, if I call [a b c] = fxn1(1, 2, 3) I get that nargin for fxn1 is 3, and nargin for fxn2 is 3, but nargout for fxn1 is 3 and nargout for fxn2 is 1. Bill On Wed, 29 Mar 2006, Geordie McBain wrote: > Does this do what you want? > >  function varargout = fxn1 (varargin) >    varargout = fxn2 (varargin{:}); >  endfunction > >  function varargout = fxn2 (varargin) >    varargout = {varargin}; >  endfunction > > I see: > > octave2.9:1> a = fxn1 (1) > a = 1 > octave2.9:2> [a, b] = fxn1 (1, 2) > a = 1 > b = 2 > > > On Tue, 2006-03-28 at 20:53 -0500, Bill Denney wrote: >> I have a function that I want to force to have a variable number of output >> arguements based on its calling function's number of output arguements. >> In other words, I want to do something like >> >> function [varargout] = fxn1(varargin) >> >>    varargout{:} = fxn2(varargin{:}); >> >> endfunction >> >> and I want fxn2 to see the same number of output arguements that fxn1 >> sees. >> >> I thought of initializing varargout like >> >> varargout = cell(1, nargout); >> >> but that didn't work.  Is there a way to do this? >> >> Bill >> > -- "I love America more than any other country in this world, and, exactly for this reason, I insist on the right to criticize her perpetually."    -- James Baldwin ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web:  http://www.octave.orgHow to fund new projects:  http://www.octave.org/funding.htmlSubscription information:  http://www.octave.org/archive.html-------------------------------------------------------------