Hello,
LabVIEW 8.0 MathScript has a built-in help infrastructure to help you understand the syntax and semantics of the language. Simply type
help
in the command window to get started. This gives a brief overview of the language as well as instructions to type
help help
for a list of help commands. Typing
help classes
will return a list of classes of MathScript functions available. When you see a class of functions you are interested in, you can type
help class
(replacing "class" with the name of the class you wish to see) in order to list the available functions within that class. Finally, you can type
help function
(replacing "function" with the name of the function you wish to see) in order to display help for that particular function. In your particular example, MathScript is reporting an error in function mtimes. This function is simply the prefix notation for the * infix operator. In order to see the proper syntax, type
help mtimes
The help says that "if a is a matrix, the number of columns in a must equal the number of rows in b." To see if there is a dimension mismatch in your case, execute your first two statements of the working script:
t = linspace(1, 2*pi, 20);
x = cos(t);
The size function will return the size of each dimension of a given matrix. Typing
help size
tells us that by default the size function returns a two-element vector containing the dimensions of the given matrix. The dimensions are returned with the first dimension listed first (i.e. the rows). Thus, we can see the number of rows and columns of a matrix by using the size function. Typing
size(t)
size(x)
returns the dimensions of each matrix. Since the dimensions are equal, we can see that the number of columns in t is not equal to the number of rows in x. This is the problem that mtimes is reporting. You can restructure your code to perform an appropriate multiplication. However, if we read the help for mtimes a little closer, we see that it performs a matrix multiplication. You probably want to perform a scalar multiplication. The second line of the help output states that the function is part of the matrixops class. By typing
help matrixops
we can see if there is a function in this class that performs a scalar multiplication. We see there is a function called "times" that performs an element-wise multiplication. Typing
help times
we can see that ".*" is the corresponding infix operator. This may be the operator you wish to use.
The second issue you reported is trying to plot two vectors on the same graph. The plot function can certainly do this. To determine the appropriate syntax, type
help plot
We can see that, for multiple plots, the plot function expects (x, y, attributes) triplets to specify each plot. We see that the attributes input is optional, so you can also use (x, y) pairs.
Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments