help-octave
[Top][All Lists]
Advanced

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

Re: function help


From: Martin Helm
Subject: Re: function help
Date: Thu, 23 Feb 2012 21:15:41 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120215 Thunderbird/10.0.2

Am 23.02.2012 20:55, schrieb damian.harty:
> And then it works. I fail at every attempt to combine them into a
> single file...
>

Because by design all the additional function definitions in the .m file
are local and hidden to the outside world. You can of course make them
visible with function handles like this

--- multif.m ---

function f = multif(name)
  if strcmp(name, "a")
    f = @__a__;
  else
    f = @__b__;
  endif
endfunction

function y= __a__(x)
  y=sin(x);
endfunction

function y=__b__(x)
  y=cos(x);
endfunction

--- end multif.m ---

octave:1> f = multif("a")
f = @__a__
octave:2> f(2)
ans =  0.90930
octave:3> f = multif("b")
f = @__b__
octave:4> f(2)
ans = -0.41615


But that's a bit off topic here.




reply via email to

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