Programmer Guide/Command Reference/EVAL Intro/EVAL: Difference between revisions
(→Syntax) |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
The <code>EVAL</code> command can be used to evaluate numerical, vector, and matrix expressions. These expressions may be built up from numerical constants, from scalar, vector, and matrix variables, and from a large number of [[Programmer Guide/Command Reference/EVAL_Intro/ | The <code>EVAL</code> command can be used to evaluate numerical, vector, and matrix expressions. These expressions may be built up from numerical constants, from scalar, vector, and matrix variables, and from a large number of [[Programmer Guide/Command Reference/EVAL_Intro/EVAL_Functions|EVAL functions]], and operators. | ||
// if the variable #v does not exist then the following command | // if the variable #v does not exist then the following command | ||
// assigns a table item to #v. | // assigns a table item to #v. | ||
Line 19: | Line 19: | ||
If the expression is syntactically ill-formed, an error (<code>EVAL</code>) or warning (<code>EVALCHECK</code>) is reported. See the example script <code>expression_check.sts</code> for details. | If the expression is syntactically ill-formed, an error (<code>EVAL</code>) or warning (<code>EVALCHECK</code>) is reported. See the example script <code>expression_check.sts</code> for details. | ||
=== Numerical Objects === | |||
{{:Programmer_Guide/Command_Reference/EVAL_Intro/Numerical_objects}} | |||
=== Numerical Comparison Operators === | === Numerical Comparison Operators === | ||
Line 53: | Line 56: | ||
{| | {| | ||
|- | |- | ||
|<code>||</code> | |<code><nowiki>||</nowiki></code> | ||
|logical or | |logical or | ||
|- | |- | ||
Line 63: | Line 66: | ||
|} | |} | ||
A C<nowiki>-</nowiki>like '<code>? :'</code> operator is also supported: | A C<nowiki>-</nowiki>like '<code>? :'</code> selection operator is also supported: | ||
result := eval 1 < 2 ? 1+2 : 1-2 // result is 3 | result := eval 1 < 2 ? 1+2 : 1-2 // result is 3 | ||
Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.: | Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.: | ||
result := eval 1 > 2 ? (5 == 5 ? 5 : 0) : (4 == 5 ? 3 : 4) // result is 4 | result := eval 1 > 2 ? (5 == 5 ? 5 : 0) : (4 == 5 ? 3 : 4) // result is 4 | ||
Latest revision as of 13:54, 1 April 2011
The EVAL
command can be used to evaluate numerical, vector, and matrix expressions. These expressions may be built up from numerical constants, from scalar, vector, and matrix variables, and from a large number of EVAL functions, and operators.
// if the variable #v does not exist then the following command // assigns a table item to #v. $#v := eval vv(1,2,3,4) // if #v is a value item, then #v remains a value item.
Syntax
An EVAL
command uses the following general syntax:
result := eval expression
or
result := evalcheck expression
An expression may be either a numerical expression, e.g.
result := eval (5 * 10) % 3
or a subcommand, e.g.
result := eval init(10,1,1)
or a combination thereof:
result := eval 5+max(fill(6,1,1))
If the expression is syntactically ill-formed, an error (EVAL
) or warning (EVALCHECK
) is reported. See the example script expression_check.sts
for details.
Numerical Objects
The following numerical objects are known to the EVAL
command. The fields of the table item table
are all numeric (you can use a parameter table). The value item value
can contain numbers, vectors or matrices. The wave item wave
is any wave item.
syntax | description | data type |
constantNumber
|
a scalar constant. E.g. 4.5 or 4
|
scalar |
table
|
the content of the whole table | vector, matrix |
table[i,*]
|
the i-th row of the table | scalar, vector |
table[*,j]
|
the j-th column of the table | scalar, vector |
table[i,j]
|
the value of the i-th row and j-th column of the table | scalar |
value
|
the content of the value item | scalar, vector, matrix |
value[i,*]
|
the i-th row of the value item | scalar, vector |
value[*,j]
|
the j-the column of the value item | scalar, vector |
value[i,j]
|
the value of the i-th row and j-th column of the value item | scalar |
wave[!signal,*]
|
the signal from all channels | vector, matrix |
wave[!signal,ch]
|
the signal from channel ch (=1,2,...) | vector |
wave[!signal,*,b,l]
|
the signal from all channels from sample b to sample b+l-1 | vector, matrix |
wave[!signal,ch,b,l]
|
the signal from channel ch from sample b to sample b+l-1 | vector |
Numerical Comparison Operators
The EVAL
command supports the following numerical comparison operators:
>
|
less than |
<
|
greater than |
<=
|
less than or equal to |
>=
|
greater than or equal to |
==
|
equal to |
!=
|
not equal to |
Note that two numbers/vectors/matrices are considered equal if (and only if)
- their dimensions are the same; and
- all elements are numerically equal.
Logical Operators
The EVAL
command supports the following logical operators:
||
|
logical or |
&&
|
logical and |
!
|
unary not |
A C-like '? :'
selection operator is also supported:
result := eval 1 < 2 ? 1+2 : 1-2 // result is 3
Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.:
result := eval 1 > 2 ? (5 == 5 ? 5 : 0) : (4 == 5 ? 3 : 4) // result is 4