Evaluate logical expression



assert(expression) evaluates a logical expression. Logical expressions evaluate to true or false. If the assert statement evaluates to false, simulation stops and returns an error.


assert(expression,errmsg) returns the specified error message string (errmsg) for the failed assert statement. If you run the test in the Test Manager, the error message appears in the simulation log. If you run the test outside the Test Manager, the message appears in the Diagnostic Viewer.


expand all

If either h or k are not 0, this assert statement fails and simulation stops.

assert(h==0 && k==0)


  • assert statements can be used in the Test Sequence and Test Assessment blocks and in Stateflow® charts. assert in Model Reference blocks works in Normal mode, but not in Rapid Accelerator mode simulations.

  • When comparing floating-point data in assert statements, consider the precision limitations associated with floating-point numbers. If you need to use floating-point data, define a tolerance for the assessment. See Floating-Point Numbers. For example, instead of assert(x == 5), assert x within a tolerance of 0.001:

    assert(abs(x-5) < 0.001)

Introduced in R2015a