Matlab Processor

This page briefly describes the Matlab processor, which is a built-in component of VisualCommander that allows the user to enter and evaluate Matlab-like code into a single code editing window. The user may associate input Data Points with local variable names, and then use these names in the code. Using the expressions in the code, the user can then create new output data points.

The language that is implemented is a subset of the Matlab language produced by the MathWorks. It is not intended to be a replacement for Matlab, but instead to provide a familiar language environment that is simple to use.

This page discusses the usage of the Matlab processor, and then discusses what features of the language that the processor supports and notes areas where certain standard features are not supported.

An online reference to the Matlab documentation can be found at The MathWorks

An open-source product that provides similar language capabilities is Octave; information is available on the web at Octave

Creation

To create a new Matlab Processor, select Processors from the menu in the Tools window and then drag "Matlab Interpreter" to an interface window in any open area. A drawer should open from the window and should have the "Interface" tab selected, and "Processors" selected from the menu at the top of the drawer. The Matlab Interpreter should appear in the list. You can change the name of the processor by double-clicking its name in the list.

Configuration

Click the "Configure" button within the drawer, with the processor selected, to open its configuration window. The window has three tabs, corresponding to the three major tasks associated with setting up a processor. The first tab, "Inputs", is where you can set up the data points that the processor uses for input values. In addition to any inputs that are set up, a "time" input is always available within the script which will contain the current UNIX timestamp (seconds since Jan 1, 1970).

Inputs

All input points are associated with an alias; that alias is the name by which the value of the input can be referenced within the matlab script. To add an input, drag a data point from the Data window onto the Inputs table. Once the input is added, set the desired alias, which must be a valid Matlab variable name. Inputs can also be removed by clicking the "-" button below the table.

The inputs tab also contains the control for changing the update rate of the processor. Only a fixed rate is currently supported; use this field to specify how often the processor should run and produce new output values.

Outputs

The outputs tab allows you to create the outputs to which you will assign values within your script. Clicking the small "+" button below the main table will open a sheet that allows you to specify the location that the new output should appear within the data heirarchy, and to give it a name. The output will initially be given an alias identical to the name you gave the output; this can be changed by double-clicking the name in the alias column.

Details of the currently selected output are found in the fields below the main table. It is important to note, first, the "Finalized" checkbox. When this is checked, the output is fully created and can no longer be substantially modified, so it is important to be certain of the output's setup before clicking this box. However, it must be checked before the output can be used in a script.

In addition to finalization, the detail allows the type, units, description and attributes of the output to be set. The Rows and Columns parameters are relevant only to matrices.

Script

The Script tab is very simple: the top box provides space for the script to be entered; the bottom provides logged messages of warnings or errors. The "Check Syntax" button does a syntax check on the code; if the code passes the syntax check, the "Enabled" checkbox will become available to check. When that box is checked, the processor will be active and will produce data. When an error occurs, the processor will automatically disable and a description of the error will print in the bottom text box.

The acceptable syntax for the processor is described below. The important point relative to the processor is the presence of variables for each input and output alias set up in the Inputs and Outputs tab. All inputs are available via their alias, and and Output's value can be set simply by assigning to their alias. Any output not assigned to will not have its value set for that update period.

Language Details

This section describes the language features of the Matlab Processor. The language is based on Matlab, and is a strict subset of it. Not all Matlab language features are included in the expression language, and some language differences exist between it and Matlab.

The reserved words, built-in variables, data types, statements, operators, and built-in functions of this language are described next. Some important differences from Matlab are also described.

Reserved words

The following words are reserved, and cannot be used as variable names. They must be used as expected in their proper place, as in Matlab: break, case, catch, continue, else, elseif, end, for, function, global, if, otherwise, persistent, return, switch, try, and while.

The following reserved words are not currently supported. They will be recognized as tokens, but will not parse correctly: case, catch, elseif, function, global, otherwise, persistent, return, switch, and try.

Implementation notes:

Free-form syntax is implemented as in Matlab (statement separators are usually optional (see below for exceptions), statements can span multiple lines, and one line can contain multiple statements. When defining matrices, either semicolons or line breaks can signify the start of new rows.

Built-in variables

The following variable and value names are special, and cannot be assigned new values: ans, eps, intmax, intmin, realmax, realmin, pi, i, j, inf, nan, computer, version, false, and true.

The following variable and value names are not supported. They will also be recognized as tokens, but will not parse properly: ans, i, j, computer, and version.

Implementation notes:

Data types

The Matlab Processor language currently supports double (IEEE 754 floating point double precision values), one- and two-dimensional matrices of doubles, and boolean (true or false). Character strings, single-precision floating point values, and strictly integer values are not supported.

Programmer's note: if one is using the MatlabEvaluator C++ object, and defines an input symbol table, any integer sd\_values in that table will be auto converted to doubles before being used.}

Statements

The following statement types are supported in the Matlab Processor:

Operators

The complete suite of Matlab operators that operate on doubles, matrices and booleans is implemented. The precedence rules are the same as for Matlab. The operators are listed in the following table.

Matrices can only have doubles as elements; because of this, embedded matrices (stacking rows or appending columns) are not supported.

Operators supported in the Matlab Processor.
operator description class
. transpose arithmetic
^ exponentiation arithmetic
* multiplication arithmetic
/ \ division (and left division) arithmetic
+ - addition, subtraction arithmetic
: sequence generation arithmetic
& | bitwise AND, OR arithmetic
< <= > >= == ~= comparison comparison
~ unary negation logical
&& || logical AND, OR (short-circuit) logical

Built-in functions

None of the Matlab built-in functions are available. The built-in functions that are available are based on the standard C math library math.h, and Princeton Satellite Systems, Inc. MatrixLib class library.

Matrix versions of functions (those that are implemented via MatrixLib) are prepended with the letter m. All functions return a single value.

The available functions are listed in the following table.

Function supported in the Matlab Processor.
function names number of inputs input argument type return type
acos, asin, atan, cos, sin, tan
acosh, asinh, atanh, cosh, sinh, tanh
exp, exp2, expm1, log, log10, log2 1 double double
log1p, logb, fabs, cbrt, sqrt
erf, erfc, lgamma, tgamma
ceil, floor, nearbyint, rint, round, trunc
atan2, hypot, pow, fmod, remainder, fmax, fmin 2 double double
mabs, mceil, mfloor, mround, mrint, msqrt
mexp, mexpm1, mlog, mlog10, mlog1p, mlog2, mlogb
msin, mcos, mtan, mcsc, msec, mcot
masin, macos, matan, macsc, masec, macot 1 matrix matrix
msinh, mcosh, mtanh, mcsch, msech, mcoth
masinh, macosh, matanh, macsch, masech, macoth
msign, mtranspose, minv, mmag, mq_pose
matan2, mcross, msolve_ax_eq_b 2 matrix matrix
mq_mult, mq_form, mq_tform

Differences from Matlab

Even in the parts of Matlab that are implemented, there are some differences between the Matlab Processor and in Matlab.

Unsupported language features

The following Matlab language features are not supported in the Matlab Processor.