Table Of Contents

MathScript Syntax

    Last Modified: December 23, 2016

    MathScript code requires that you adhere to specific syntax guidelines.

    Code Type Syntax Guidelines Examples
    Array White spaces or commas separate array elements. Semicolons or line breaks separate rows of an array.

    [1 2 3] or [1, 2, 3] define an array with three columns, each with one value.

    [1; 2; 3] defines an array with three rows, each with one value.

    Structure Structure syntax is <variable>.<field name>.
    point.x = 3.0;
    point.y = 5.0;
    Defines a structure with two fields that describe a point within a graph.

    point is a scalar structure with the fields x and y. Each field has an assigned numeric value.

    Structure Array Structure array syntax is <variable(n)>.<field name>.
    point(1).x = 3.0;
    point(1).y = 4.0;
    point(2).x = 3.5;
    point(2).y = 5.0;

    Defines two structure elements that describe points.


    Unassigned array elements have empty array field values. Fields have at least 2 dimensions if unassigned array elements are used.

    Variable Name A variable name cannot begin with an underscore, a white space, or a digit. a


    Numeric Value
    • Periods separate decimals.
    • Ranges define vectors by start value, increment, and end value. The syntax for a range is start: [step:] end. Start, step, and end are constant scalar numbers of either integer or floating-point data types, or characters. MathScript uses a step size of 1 by default. If an input is a character data type, the output is also a character data type.
    • Either i or j represent the imaginary unit equal to the square root of -1.

    Separated decimals: 2.1

    Ranges: 1:1:10

    Complex numbers: 2+3i or 2+3j

    Comment Comment lines begin with a % character. % This is a comment.
    • Semicolons, commas, or line breaks separate several commands. Suppress output with semicolons.
    • Three dots at the end of a line continue a command on a new line.
    • MathScript uses short-circuit evaluation to evaluate compound logical expressions.

    Command separation: a=abs(b), c=sin(d)

    Continued command:
    a=abs(b) ...
    + abs(c)

    Short-circuit evaluation: The command if 0 == 0 || abs(a) == 1 does not execute abs(a) because the first part of the expression already is TRUE. Similarly, the command if 0 ~= 0 && abs(a) == 1 does not execute abs(a) because the first part of the expression already is FALSE.

    Recently Viewed Topics