Programmer Guide/Command Reference/EVAL: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 28: Line 28:
|-
|-
|''constantNumber''
|''constantNumber''
|a scalar constant. E.g. <code>4.5</code> or <code>4</code>
|a scalar constant. E.g. '''4.5''' or '''4'''
|scalar
|scalar
|-
|-
''table''
|''table''
|the content of the whole table
|the content of the whole table
|vector, matrix
|vector, matrix
|-
|-
|''table''[''i'',*]'' or ''table''[''i'',]
|''table''[''i'',*] or ''table''[''i'',]
|the i<nowiki>-</nowiki>th row of the table
|the ''i''-th row of the table
|scalar, vector
|scalar, vector
|-
|-

Revision as of 10:29, 31 March 2011

Introduction

The EVAL command can be used to evaluate numerical expressions. These expressions may be built up from numerical constants, from scalar, vector, and matrix variables, and from a large number of functions and operators.

Syntax

An EVAL command uses the following general syntax:

result := eval expression

or

result := evalcheck expression
result
This is the target to be assigned with the result of the evaluation of the numerical expression. The result can be a shell variable, a Programmer_Guide/Shell_Items or a numerical object
expression
The numerical expression to be evaluated. The expression consists of numerical objects, functions and operators.

Examples:

  • result := eval (5 * 10) % 3
  • result := eval init(10,1,1)
  • result := eval 5+max(fill(6,1,1))

If the expression is syntactically ill-formed an error (EVAL) or warning (EVALCHECK) is reported and the assignment is not performed (content of result is not changed). 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 (extended table or 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,*] or table[i,] the i-th row of the table scalar, vector
table[*,j]

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,*]

value[i,]

the i-th row of the value item scalar, vector
value[*,j]

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,*]

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)

  1. their dimensions are the same; and
  2. 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


EVAL subcommands

Examples

For an extensive list of examples, see the script eval_examples.sts: Programmer Guide/Command Reference/EVAL Examples/EVAL Examples

History

The EVAL command was added to the S_TOOLS-STx language in version 3.7.0. The EVAL command replaces and extends the EVALUATE command. If the EVAL command is not assigning to an existing item, a table is assigned. Note that the current maximum number of arguments is 64 (S_TOOLS-STx version 3.8.0). As of version 3.7.0, S_TOOLS-STx has more numerical objects than just the scalars INT and NUM.

Navigation menu

Personal tools