Next: , Up: Octave Features


5.1 Functions defined on the command-line

Functions can be defined by entering code on the command line, a feature not supported by Matlab. For example, you may type:

     octave:1> function s = hello_string (to_who)
     > ## Say hello
     > if nargin<1, to_who = "World"; end
     > s = ["Hello ",\
     >      to_who];
     > endfunction
     octave:2> hello_string ("Moon")
     ans = Hello Moon