help-octave
[Top][All Lists]
Advanced

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

Functions as variables


From: Christoph Dalitz
Subject: Functions as variables
Date: Thu, 16 Oct 2003 11:51:06 +0200

Hello,

how can I pass a function as a variable input argument to another function?
I have tried the following, but it does not work:

        function fplot(x,f)
          y = zeros(1,length(x));
          for i = 1:length(x)
            y(i) = f(x(i));
          endfor
          plot(x,y);
        endfunction

When calling this function, eg. with

        f(0:0.1:5,sin);

I get an error

        error: sin: too few arguments
        error: evaluating argument list element number 2
        error: evaluating index expression near line 8, column 1

Thanks,

Christoph dalitz



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