Table Of Contents

Retrieving Return Values of MathScript Expressions

    Last Modified: December 23, 2016

    Use the ans variable to retrieve the return value of the previous MathScript expression. If an expression has more than one result, ans returns only one result. If you use two expressions in one row, e.g. 5; sin(0.5), ans contains the result of the last expression. ans can contain values of any data type and any size.

    The following procedure demonstrates how to get the value of an expression in the variable ans in the MathScript Node using a specific example. The example calculates the sine of the array values stored in the variable ans. The steps you need to take to complete your specific task might be different than the following steps.

    1. In the Project Files tab, add a VI.
    2. Add a MathScript Node to the diagram and then enter the following expression in the node: [0.1,0.3;0.75,1]
    3. Click Run. MathScript stores the array values in the variable ans.
    4. Enter the following code into a new line of the MathScript Node: A = sin(ans).
    5. Right-click the MathScript Node border and select Create»Output. Name the output A.
    6. Place an indicator on the diagram by right-clicking A and selecting Create Indicator.
    7. Switch to the panel.
    8. Drag the indicator in the unplaced items tray to the panel.
    9. Click Run. MathScript calculates the sine of the array values that are stored in the variable ans. Enlarge the indicator by dragging a corner in order to view all results.

    Recently Viewed Topics