From help-octave-request at bevo dot che dot wisc dot edu Tue Jan 20 16:15:33 2004 Subject: Re: matlab nargin() function alternative in octave? From: taltman at lbl dot gov To: Sharene Bungay cc: help-octave at bevo dot che dot wisc dot edu Date: Tue, 20 Jan 2004 22:06:39 +0000 (UTC) This looks like it can be handled using 'varargin'. It can allow your function to accept a variable number of arguments. You'll just have to do some variable type-checking. HTH, ~Tomer On Jan 20, 2004 at 10:04am, Sharene Bungay wrote: sbunga >Date: Tue, 20 Jan 2004 10:04:44 -0500 (EST) sbunga >From: Sharene Bungay sbunga >To: John W. Eaton sbunga >Cc: help-octave at bevo dot che dot wisc dot edu sbunga >Subject: Re: matlab nargin() function alternative in octave? sbunga >Resent-Date: Tue, 20 Jan 2004 09:04:48 -0600 sbunga >Resent-From: help-octave at bevo dot che dot wisc dot edu sbunga > sbunga >Hi, thanks for your reply. sbunga >I believe it can only accept string arguments under matlab. sbunga >An example is as follows: Lets assume that I define sbunga >an algorithm that uses regression as one of its steps. sbunga >I code the algorithm to call reg(x1,x2,...) with the sbunga >correct number of arguments. reg() in turn is conditionally sbunga >defined to take either say, 2 or 3 arguments, depending sbunga >on some user-set parameter. I could then have my algorithm sbunga >test something like: sbunga > sbunga >if (nargin('reg')==3) sbunga > sigma=0.001; sbunga > reg(x1,x2,sigma); sbunga >else sbunga > reg(x1,x2); sbunga >end sbunga > sbunga >Now if I were coding this, I would probably just have a global sbunga >flag something like: sbunga > sbunga >if (userselect==reg1) sbunga > regfunc1(x1,x2,sigma); sbunga >else sbunga > regfunc2(x1,x2); sbunga >end sbunga > sbunga >But unfortunately, I need to use existing code that makes sbunga >use of the nargin('string') functionality. sbunga > sbunga >TIA. sbunga >Sharene. sbunga > sbunga >On Mon, 19 Jan 2004, John W. Eaton wrote: sbunga > sbunga >> On 19-Jan-2004, Sharene Deanne Bungay wrote: sbunga >> sbunga >> | I have some matlab code that I would very much like sbunga >> | to use under octave. Unfortunately, the matlab code sbunga >> | relies on matlab's ability to pass a function as an sbunga >> | argument to nargin ( eg. nargin('sin')) and have it return sbunga >> | the number of arguments expected by that function. sbunga >> | I know that under octave, nargin is only a local scope scalar sbunga >> | valid inside a given function, but does there exist a means sbunga >> | under octave to get the number of expected arguments to a function sbunga >> | (outside the scope of that function)? sbunga >> | sbunga >> | (This functionality is required since I have functions that are sbunga >> | conditionally defined to take different arguments, and subsequent sbunga >> | behaviour requires knowledge of the number of arguments. Rewriting sbunga >> | the code to use global variables instead of relying on the form of sbunga >> | the function definitions would be too extensive, so any help sbunga >> | on this matter would be *GREATLY* appreciated.) sbunga >> sbunga >> Can you post an actual example that uses this functionality so we can sbunga >> see how you are using it and why it is needed? sbunga >> sbunga >> The Matlab documentation shows that nargin and nargout may accept sbunga >> string arguments. Are function handles also allowed? sbunga >> sbunga >> Thanks, sbunga >> sbunga >> jwe sbunga >> sbunga > sbunga > sbunga > sbunga >------------------------------------------------------------- sbunga >Octave is freely available under the terms of the GNU GPL. sbunga > sbunga >Octave's home on the web: http://www.octave.org sbunga >How to fund new projects: http://www.octave.org/funding.html sbunga >Subscription information: http://www.octave.org/archive.html sbunga >------------------------------------------------------------- sbunga > sbunga > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------