You can include MathScript commands in the Block diagram of a VI in a MathScript node which is available on the mathscript_example.vi, followed by comments. You will soon be guided through the development of this VI. palette. Let us look at a simple example. Below are the Front panel and the Block diagram of
Comments to the Front panel:
· To the left of the Front panel are the scalar controls (or numbers in DBL (double) formal), a and b, and two real matrices, A and x.
· Further to the right are indicators, z and y. z is a real scalar. y is a real matrix.
· error out is a cluster indicator displaying any MathScript errors on the Front panel.
Comments to the Block diagram:
· a, b, A, and x are names of the inputs to the MathScript. The data type of a and b are real scalars (we may also say doubles). A and x are real matrices.
· Matrices are used, not arrays, in these matrix based calculations! Connecting arrays to the MathScript node in stead of matrices in such applications will cause an error.
Scalars and matrices are probably the most common data types in MathScript applications. However, you can also use arrays and strings (text). The data type of a MathScript node input or output are set via right-clicking on the input/output, and selecting the sata type from a list.
The MathScript node contains three commands: One comment, which starts with a percent sign, and two ordinary commmands separated by semicolon.
· The MathScript contains an error cluster output which here is wired to a front panel indicator. It is wise to include an error cluster in the early stage of the development of a VI containing a MathScript node as it helps you to find errors. These error may otherwise be quite hard to find.
Note: If you want to include a matrix constant in the Block diagram, you may face trouble because there is no matrix constant on the Functions palette (this is a little strange...). In this case, you may in stead intermediately create a matrix control on the Front panel, and then change its Block diagram terminal from control to constant via right-click on the terminal. If you really want to use matrix constants in the Block diagram, you may consider creating or defining the matrix directly in the MathScript node. For example you can type
M = [1,2;3,4]
which creates a 2x2 matrix with 1 and 2 in the first row, and 3 and 4 in the second row.
Now, it's your turn. To create a VI similar to mathscript_example.vi:
Enter values to these Front panel elements as on the Front panel of mathscript_example.
Then connect the ouputs y and z to their respective indicators.
Note: This VI will run the code once since the code is not inside any While loop. If you want, you can add a While loop, a Stop button, and a Metronome. If you do not want to add a While loop, but still want to run your VI continuously while testing it, click the Run Continuously button in stead of the Run button in the toolbar. |
No comments:
Post a Comment