help-octave
[Top][All Lists]
Advanced

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

Re: matlab nargin() function alternative in octave?


From: Sharene Bungay
Subject: Re: matlab nargin() function alternative in octave?
Date: Tue, 20 Jan 2004 10:04:44 -0500 (EST)

Hi, thanks for your reply.
I believe it can only accept string arguments under matlab.
An example is as follows: Lets assume that I define
an algorithm that uses regression as one of its steps.
I code the algorithm to call reg(x1,x2,...) with the
correct number of arguments. reg() in turn is conditionally
defined to take either say, 2 or 3 arguments, depending
on some user-set parameter. I could then have my algorithm
test something like:

if (nargin('reg')==3)
        sigma=0.001;
        reg(x1,x2,sigma);
else
        reg(x1,x2);
end

Now if I were coding this, I would probably just have a global
flag something like:

if (userselect==reg1)
        regfunc1(x1,x2,sigma);
else
        regfunc2(x1,x2);
end

But unfortunately, I need to use existing code that makes
use of the nargin('string') functionality.

TIA.
Sharene.

On Mon, 19 Jan 2004, John W. Eaton wrote:

> On 19-Jan-2004, Sharene Deanne Bungay <address@hidden> wrote:
> 
> | I have some matlab code that I would very much like
> | to use under octave. Unfortunately, the matlab code
> | relies on matlab's ability to pass a function as an
> | argument to nargin ( eg. nargin('sin')) and have it return
> | the number of arguments expected by that function.
> | I know that under octave, nargin is only a local scope scalar
> | valid inside a given function, but does there exist a means
> | under octave to get the number of expected arguments to a function
> | (outside the scope of that function)?
> | 
> | (This functionality is required since I have functions that are
> | conditionally defined to take different arguments, and subsequent
> | behaviour requires knowledge of the number of arguments. Rewriting
> | the code to use global variables instead of relying on the form of
> | the function definitions would be too extensive, so any help
> | on this matter would be *GREATLY* appreciated.)
> 
> Can you post an actual example that uses this functionality so we can
> see how you are using it and why it is needed?
> 
> The Matlab documentation shows that nargin and nargout may accept
> string arguments.  Are function handles also allowed?
> 
> Thanks,
> 
> jwe
> 



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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