LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript Nugget #3: Data Type Highlighting in the MathScript Node

Since LabVIEW 8.6, the MathScript Node has boasted an extremely useful feature: syntax highlighting. This allows you to quickly distinguish different parts of your script by looking at the color of the text. In 2009, this idea has been extended and the node features a new highlighting mode: data type highlighting.

 

You can enable this mode by right-clicking on a MathScript Node and selecting Script Highlighting≫Data Types. Now LabVIEW will change the color and style of your text to highlight the data type of each variable. This is designed to function in the same way as LabVIEW’s wire coloring scheme. The color shows the representation of your variable: green for Boolean, blue for integer, orange for floating point. The style (like the wire width) shows the dimension of your variable: plain text for scalar, italics for 1D arrays, bold and italics for 2D arrays. And if you don’t like these default settings, you can customize them to your heart’s content in the MathScript page of the Tools≫Options dialog.

 

Why is this feature useful? It’s about more than just changing a color scheme when you get bored of the old syntax highlighting colors. It can be an extremely powerful tool for debugging and optimizing your MathScript code. I find it particularly useful for finding places in my scripts where MathScript has selected a type that’s larger than necessary. For example, the ‘sqrt’ function always returns a complex number in case the input is negative. This means that any code later in your script that uses the output of ‘sqrt’ will operate on complex numbers, which can have performance implications because of the additional memory used for storage and because it can cause less optimal algorithms to be used downstream. If you turn on data type highlighting you will see that the output of ‘sqrt’ is colored red, which is the default color of complex numbers in MathScript (differing from the orange default in LabVIEW so that complex numbers are more obvious). If you know that the input is always going to be positive and you are concerned about performance, you can optimize this call by converting the result using the ‘real’ function. Downstream code will run faster and use less memory.

 

I encourage you to play with this feature on your scripts in LabVIEW 2009 to see if you can squeeze more performance out of your MathScript nodes!

 

jattas

LabVIEW MathScript R&D

 

ps Check out previous MathScript Nuggets here.

 

 

Message 1 of 1
(6,273 Views)