Alan E
Alan E

Reputation: 400

How to see function body in GNU Octave

Is there a way in GNU Octave to print source code of a user-defined function?

For example, I've defined a function in the interactive prompt:

octave:nn> function y = f(x); y = x; endfunction;

Now is there a way to look up this function definition later in the prompt? Something like

octave:nn> showsource("f")
ans = function y = f(x); y = x; endfunction;

Upvotes: 4

Views: 2848

Answers (2)

siko1056
siko1056

Reputation: 81

For displaying the content of any function, use the type function:

    >> function y = f(x); y = x; endfunction;
    >> type ("f")
    f is the command-line function:

    function y = f (x)
      y = x;
    endfunction

Upvotes: 8

am304
am304

Reputation: 13886

If the function is defined with inline, you can use formula or char to see the body of the function:

>> f = inline("x");
>> formula(f)
ans = x
>> char(f)
ans = x

Upvotes: 3

Related Questions