Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 239

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Evaluation - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Expressions.html#Expressions" title="Expressions">
<link rel="next" href="Statements.html#Statements" title="Statements">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Evaluation"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Statements.html#Statements">Statements</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Expressions.html#Expressions">Expressions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>

<h2 class="chapter">9 Evaluation</h2>

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

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

<!-- eval src/oct-parse.cc -->
   <p><a name="doc_002deval"></a>

<div class="defun">
&mdash; Built-in Function:  <b>eval</b> (<var>try</var>)<var><a name="index-eval-680"></a></var><br>
&mdash; Built-in Function:  <b>eval</b> (<var>try, catch</var>)<var><a name="index-eval-681"></a></var><br>
<blockquote><p>Parse the string <var>try</var> and evaluate it as if it were an Octave
program.  If that fails, evaluate the optional string <var>catch</var>. 
The string <var>try</var> is evaluated in the current context,
so any results remain available after <code>eval</code> returns.

        <p>The following example makes the variable <var>a</var> with the approximate
value 3.1416 available.

     <pre class="example">          eval("a = acos(-1);");
</pre>
        <p>If an error occurs during the evaluation of <var>try</var> the <var>catch</var>
string is evaluated, as the following example shows:

     <pre class="example">          eval ('error ("This is a bad example");',
                'printf ("This error occurred:\n%s\n", lasterr ());');
               -| This error occurred:
                  This is a bad example
</pre>
        <p>Consider using try/catch blocks instead if you are only using <code>eval</code>
as an error-capturing mechanism rather than for the execution of arbitrary
code strings. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002devalin.html#doc_002devalin">evalin</a>. 
</p></blockquote></div>

<ul class="menu">
<li><a accesskey="1" href="Calling-a-Function-by-its-Name.html#Calling-a-Function-by-its-Name">Calling a Function by its Name</a>
<li><a accesskey="2" href="Evaluation-in-a-Different-Context.html#Evaluation-in-a-Different-Context">Evaluation in a Different Context</a>
</ul>

   </body></html>