Typing a TAB character (ASCII code 9) on the command line causes Octave to attempt to complete variable, function, and file names. Octave uses the text before the cursor as the initial portion of the name to complete.
For example, if you type `fu' followed by TAB at the Octave prompt, Octave will complete the rest of the name `function' on the command line (unless you have other variables or functions defined that begin with the characters `fu'). If there is more than one possible completion, Octave will ring the terminal bell to let you know that your initial sequence of characters is not enough to specify a unique name. To complete the name, you may either edit the initial character sequence (usually adding more characters until completion is possible) or type another TAB to cause Octave to display the list of possible completions.
When running interactively, Octave saves the commands you type in an internal buffer so that you can recall and edit them. Emacs and vi editing modes are available with Emacs keybindings enabled by default.
When Octave exits, the current command history is saved to the file `~/.octave_hist', and each time Octave starts, it inserts the contents of the `~/.octave_hist' file in the history list so that it is easy to begin working where you left off.
Octave includes a limited amount of support for organizing data in structures. The current implementation uses an associative array with indices limited to strings, but the syntax is more like C-style structures. Here are some examples of using data structures in Octave.
octave:1> x.a = 1; x.b = [1, 2; 3, 4]; x.c = "string"; octave:2> x.a x.a = 1 octave:3> x.b x.b = 1 2 3 4 octave:4> x.c x.c = string
octave:1> y = x y = <structure: a b c>
octave:1> x.b.d = 3 x.b.d = 3 octave:2> x.b x.b = <structure: d> octave:3> x.b.d x.b.d = 3
octave:1> function y = f (x) > y.re = real (x); > y.im = imag (x); > endfunction octave:2> f (rand + rand*I); ans = <structure: im re> octave:3> ans.im, ans.re ans.im = 0.93411 ans.re = 0.56234
octave:1> [x.u, x.s(2:3,2:3), x.v] = svd ([1, 2; 3, 4]) x.u = -0.40455 -0.91451 -0.91451 0.40455 x.s = 0.00000 0.00000 0.00000 0.00000 5.46499 0.00000 0.00000 0.00000 0.36597 x.v = -0.57605 0.81742 -0.81742 -0.57605 octave:8> x x = <structure: s u v>
is_structto determine whether a given value is a data structure. For example
is_struct (x)returns 1 if the value of the variable x is a data structure.
This feature should be considered experimental, but you should expect it to work. Suggestions for ways to improve it are welcome.
Octave's `&&' and `||' logical operators are evaluated in a short-circuit fashion (like the corresponding operators in the C language) and work differently than the element by element operators `&' and `|'.
Octave includes the C-like increment and decrement operators `++' and `--' in both their prefix and postfix forms.
For example, to pre-increment the variable x, you would write
++x. This would add one to x and then return the new
value of x as the result of the expression. It is exactly the
same as the expression
x = x + 1.
To post-increment a variable x, you would write
This adds one to the variable x, but returns the value that
x had prior to incrementing it. For example, if x is equal
to 2, the result of the expression
x++ is 2, and the new
value of x is 3.
For matrix and vector arguments, the increment and decrement operators work on each element of the operand.
It is not currently possible to increment index expressions. For
example, you might expect that the expression
increment the fourth element of the vector v, but instead it
results in a parse error. This problem may be fixed in a future
release of Octave.
Octave supports a limited form of exception handling modelled after the
unwind-protect form of Lisp. The general form of an
unwind_protect block looks like this:
unwind_protect body unwind_protect_cleanup cleanup end_unwind_protect
Where body and cleanup are both optional and may contain any Octave expressions or commands. The statements in cleanup are guaranteed to be executed regardless of how control exits body.
unwind_protect statement is often used to reliably restore
the values of global variables that need to be temporarily changed.
Octave has a real mechanism for handling functions that take an unspecified number of arguments, so it is no longer necessary to place an upper bound on the number of optional arguments that a function can accept.
Here is an example of a function that uses the new syntax to print a header followed by an unspecified number of values:
function foo (heading, ...) disp (heading); va_start (); while (--nargin) disp (va_arg ()); endwhile endfunction
va_start() positions an internal pointer to the first
unnamed argument and allows you to cycle through the arguments more than
once. It is not necessary to call
va_start() if you do not plan
to cycle through the arguments more than once.
va_arg() returns the value of the next available
argument and moves the internal pointer to the next argument. It is an
error to call
va_arg() when there are no more arguments
It is also possible to use the keyword all_va_args to pass all unnamed arguments to another function.
Octave also has a real mechanism for handling functions that return an unspecified number of values, so it is no longer necessary to place an upper bound on the number of outputs that a function can produce.
Here is an example of a function that uses the new syntax to produce `N' values:
function [...] = foo (n) for i = 1:n vr_val (i); endfor endfunction
Octave includes LSODE and DASSL for solving systems of stiff differential and differential-algebraic equations. These functions are built in to the interpreter.