Go to the first, previous, next, last section, table of contents.


What features are unique to Octave?

Command and variable name completion

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.

Command history

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.

Data structures

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.

This feature should be considered experimental, but you should expect it to work. Suggestions for ways to improve it are welcome.

Short-circuit boolean operators

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 `|'.

Increment and decrement operators

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 x++. 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 v(4)++ would 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.

Unwind-protect

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.

The unwind_protect statement is often used to reliably restore the values of global variables that need to be temporarily changed.

Variable-length argument lists

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

Calling 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.

The function 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 available.

It is also possible to use the keyword all_va_args to pass all unnamed arguments to another function.

Variable-length return lists

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

Built-in ODE and DAE solvers

Octave includes LSODE and DASSL for solving systems of stiff ordinary differential and differential-algebraic equations. These functions are built in to the interpreter.


Go to the first, previous, next, last section, table of contents.