Graphical Instrument Scripting: From Equations to XY Data

Graphical Instrument Scripting connects a text-based numerical calculation to a graphical instrument display. You supply parameters, evaluate an equation at selected inputs, and send the resulting coordinate pairs to an XY Graph. The implementation here assumes a legacy LabVIEW installation that supports MathScript and has the required module installed. The focus is the calculation-to-display connection, rather than data acquisition or repeated execution.

Connect the script to the diagram

A MathScript Node is a block-diagram structure that executes text-based numerical code and exchanges values through named terminals. Writing a variable inside the script does not automatically create a terminal on the diagram.


Add input terminals on the node's left border for externally supplied parameters. Add output terminals on its right border for results needed elsewhere. Match each terminal name exactly to its script variable, including capitalization. Assign each requested output during the calculation.


Set output types to match the results. A single real number uses a scalar floating-point type; a sequence of real samples uses a one-dimensional double-precision array, commonly shown as DBL 1D. A scalar and an array containing one value still have different shapes.


Scalar parameters enter a MathScript Node whose two array outputs are bundled for an XY Graph.


Evaluate an equation across an array

The governing relationship is a point-by-point calculation:


yi=f(xi;parameters)y_i=f(x_i;\text{parameters})


An element-wise operation applies an operation separately to corresponding array entries. In MathScript, dotted operators distinguish these calculations from matrix operations.


Intended calculation

MathScript operator

Meaning for arrays

Multiply corresponding entries

.*

One product per corresponding pair

Divide corresponding entries

./

One quotient per corresponding pair

Raise each entry to a power

.^

One powered value per entry

Multiply matrices

*

Matrix product; scalar multiplication also works


For example, let displacement xx be measured in metres and force follow


F=kx2+b,k=200 N/m2,b=3 N.F=kx^2+b,\qquad k=200\ \text{N/m}^2,\quad b=3\ \text{N}.


With scalar inputs k and b, the script is:


MATLAB
x = linspace(0, 0.2, 3);
F = k*x.^2 + b;


The function linspace(start, stop, N) creates NN equally spaced values, including both endpoints. Here, x contains 00, 0.10.1, and 0.20.2 m. Squaring each entry, multiplying by 200200, and adding 33 produces forces of 33, 55, and 1111 N. Scalar multiplication by k is valid without a dot.



Build the XY Graph input

For the single-plot representation used here, an XY Graph accepts a cluster whose first element is the x array and whose second element is the y array. Use Bundle to create that cluster, then wire its output to the graph.


The pairing rule is


(xi,yi),i=1,2,…,N.(x_i,y_i),\qquad i=1,2,\ldots,N.


Check that both arrays contain the intended NN samples in corresponding order. An XY Graph uses the supplied x coordinates; they need not be equally spaced. It does not infer physical coordinates from array positions.



For several plots, bundle each plot's x and y arrays separately, then build an array of those clusters. Each plot can have its own sampling locations.

Check the numerical meaning

Numerical arrays do not explain their physical units by themselves. Keep a consistent unit convention in the calculation and label the graph axes accordingly. Changing an axis label from metres to millimetres does not multiply the underlying numbers by 10001000.


Before trusting a curve, calculate one point by hand, inspect array lengths, and check the endpoints. If points are joined by lines, their array order determines the connection order. A smooth-looking line alone does not establish that coordinates, units, or equations are correct.


What to remember

  • Match script variables to named terminals and suitable output types.
  • Use element-wise operators for point-by-point array calculations.
  • Bundle x first and y second, preserving corresponding entries.
  • Convert numerical values when changing units, then label the axes.

Example: Displaying a Predicted Actuator Motion

An actuator's predicted position over a short test is


d(t)=d0+v0t+12at2,d(t)=d_0+v_0t+\frac{1}{2}at^2,


where d0=0.015 md_0=0.015\ \text{m}, v0=0.020 m/sv_0=0.020\ \text{m/s}, and a=0.030 m/s2a=0.030\ \text{m/s}^2. Treat acceleration as constant over 0≤t≤2.00 s0\leq t\leq2.00\ \text{s}. Use a legacy LabVIEW installation with MathScript support.


The scalar parameters enter a MathScript Node through terminals named d0, v0, and a.


a) Write a script that creates five equally spaced time samples, including both endpoints, and calculates the position array. Specify the output terminals and their types.


Five samples spanning both endpoints create ________ equal intervals. Their spacing is


Δt=2.00−05−1=0.50 s.\Delta t=\frac{2.00-0}{5-1}=0.50\ \text{s}.


Use linspace to generate those samples, then evaluate the motion model with an element-wise square:


MATLAB
t = linspace(0, 2.00, 5);
d = d0 + v0*t + 0.5*a*t.^2;


The resulting time array is


t=[0,0.50,1.00,1.50,2.00] s.t=[0,0.50,1.00,1.50,2.00]\ \text{s}.


Add output terminals named t and d. Configure both as one-dimensional DBL arrays because each contains five real-valued samples. The inputs remain scalars. The expression t.^2 squares each time sample; multiplication by the scalar coefficients then applies the physical model to every entry.


b) Calculate the position at t=1.50 st=1.50\ \text{s} by hand to check the script.


The time 1.50 s1.50\ \text{s} is the ________ stored sample. Evaluate the initial position, velocity contribution, and acceleration contribution separately before adding them.


v0t=(0.020 m/s)(1.50 s)=0.030 m,12at2=12(0.030 m/s2)(1.50 s)2=(0.015)(2.25) m=0.03375 m,d(1.50)=0.015+0.030+0.03375=0.07875 m.\begin{aligned} v_0t&=(0.020\ \text{m/s})(1.50\ \text{s})=0.030\ \text{m},\\ \frac{1}{2}at^2&=\frac{1}{2}(0.030\ \text{m/s}^2)(1.50\ \text{s})^2\\ &=(0.015)(2.25)\ \text{m}=0.03375\ \text{m},\\ d(1.50)&=0.015+0.030+0.03375\\ &=0.07875\ \text{m}. \end{aligned}


Every contribution has units of metres. The fourth entry of the scripted position array should therefore be 0.07875 m0.07875\ \text{m}, apart from floating-point rounding.


c) Prepare an XY Graph with time in seconds and position in millimetres. Describe the wiring and calculate the final displayed coordinate.


Convert the position values before sending them to the graph. Merely changing an axis label would leave the numerical values in metres.


MATLAB
d_mm = 1000*d;


Add d_mm as a one-dimensional DBL output. Use Bundle with t as its first element and d_mm as its second element, then wire the cluster to the XY Graph. Label the horizontal axis Time (s) and the vertical axis Position (mm).


At the final sample, t=2.00 st=2.00\ \text{s}:


d(2.00)=0.015+(0.020)(2.00)+12(0.030)(2.00)2=0.015+0.040+0.060=0.115 m,dmm(2.00)=(0.115 m)(1000 mm/m)=115 mm.\begin{aligned} d(2.00)&=0.015+(0.020)(2.00)+\frac{1}{2}(0.030)(2.00)^2\\ &=0.015+0.040+0.060\\ &=0.115\ \text{m},\\ d_{\text{mm}}(2.00)&=(0.115\ \text{m})(1000\ \text{mm/m})\\ &=115\ \text{mm}. \end{aligned}


The final displayed coordinate is (2.00 s,115 mm)(2.00\ \text{s},115\ \text{mm}). Both graph-input arrays contain five entries, and the conversion preserves their sample order.

A legacy LabVIEW VI with MathScript support models a sensor voltage using the following script. The entries of x represent displacement in metres, and the coefficient is 3.5 V/m3.5\ \text{V/m}.


MATLAB
x = linspace(0, 0.6, 4);
y = 3.5*x;


Which declaration for the node's y output preserves all four values, their fractional parts, and their one-dimensional shape without conversion?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A LabVIEW VI computes a physical model in a script and plots the result as paired coordinates on the front panel. Match each element or operator used in that VI to the description of its role.

Match each term
A.

Generates values starting at a and stepping by h, stopping at the last value that does not pass b

B.

Combines a horizontal-coordinate array and a vertical-coordinate array into the single cluster a paired-coordinate plot accepts

C.

A block-diagram structure that runs text-based, .m-style commands between its input and output terminals

D.

Multiplies two arrays entry by entry instead of forming a matrix product

E.

Returns n evenly spaced values from a to b, including both endpoints

F.

A front-panel indicator that plots each vertical value against its own paired horizontal value, so samples need not be evenly spaced

The .* operator

XY Graph

Colon range a:h:b

Bundle function

linspace(a, b, n)

MathScript Node

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

In a legacy LabVIEW MathScript Node, x = [0.2 0.5 0.9]; stores three displacements in metres. A scalar input k equals 40 N/m240\ \text{N/m}^2. The force model is Fi=kxi2F_i=kx_i^2 for each displacement sample.


Which statement produces the required three-entry force vector in newtons?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice