Creating a MATLAB Script

Note  You must have MATLAB installed on your computer to use MATLAB script nodes because MATLAB script nodes invoke the MATLAB script server to execute MATLAB scripts. Because LabVIEW uses ActiveX technology to implement MATLAB script nodes, they are available only on the Windows platform.

Complete the following steps to create and run a VI that uses a MATLAB script.

  1. Select Functions»Mathematics»Formula»MATLAB Script and drag out a region to place the MATLAB script node on the block diagram.
  2. Use the Operating or Labeling tool to enter the following script in the MATLAB script node.

    a=rand(50)

    surf(a)

    This simple MATLAB script creates a matrix of random values, plots that information to a graph, displays the matrix in MATLAB, and presents the generated random values on the LabVIEW front panel.
  3. Add inputs and outputs for variables. On the block diagram, right-click the MATLAB script node frame and select Add Output from the shortcut menu. Enter a to add an output for the a variable in the MATLAB script. By default the MATLAB script node includes one input and one output for the error in and error out parameters.
  4. Verify the data type of the inputs and/or outputs. In MATLAB, the default data type for any new input or output is Real. Right-click the a output and select Choose Type»Real Matrix from the shortcut menu.
  5. Create controls and indicators for each input and output. Right-click the a output and the error out output and select Create»Indicator from the shortcut menu. LabVIEW creates indicators for a and error out on the front panel and wires terminals to these outputs on the block diagram.
  6. On the front panel, resize your a indicator so you can see the numbers generated by the script when you run the VI.
  7. Run the VI. LabVIEW launches MATLAB. A new MATLAB window appears, labeled Figure No. 1, that displays the matrix. LabVIEW displays the values that make up this matrix in the a indicator on the front panel.

Just as with a regular formula node, you can display a scrollbar within your script node by right-clicking the node and selecting Show»Scrollbar. A scrollbar appears on the right side of your script node.

Note  MATLAB code inside a script node functions identically as it would in the MATLAB environment.

Refer to Debugging a HiQ or MATLAB Script for information about debugging HiQ script.