- publishing free software manuals
GNU Octave Manual Version 3
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
ISBN 095461206X
RRP £24.95 ($39.95)

Get a printed copy>>>

9 Evaluation

Normally, you evaluate expressions simply by typing them at the Octave prompt, or by asking Octave to interpret commands that you have saved in a file.

Sometimes, you may find it necessary to evaluate an expression that has been computed and stored in a string, which is exactly what the eval function lets you do.

Built-in Function: eval (try, catch)
Parse the string try and evaluate it as if it were an Octave program. If that fails, evaluate the optional string catch. The string try is evaluated in the current context, so any results remain available after eval returns.

The following example makes the variable a with the approximate value 3.1416 available.

eval("a = acos(-1);");

If an error occurs during the evaluation of try the catch string is evaluated, as the following example shows:

eval ('error ("This is a bad example");',
      'printf ("This error occurred:\n%s", lasterr ());');
     -| This error occurred:
        error: This is a bad example
ISBN 095461206XGNU Octave Manual Version 3See the print edition