Create an Interface for MATLAB to define calls to a MATLAB function or script.
On the
Project Files
tab, select
New»Interface for MATLAB®.
In the Interface for MATLAB, use one of the following options to specify a function or script you want to call:
Click the
...
button and select a MATLAB file on disk.
Enter the name of a MATLAB function or the filename of a MATLAB file on the MATLAB search path. Use this option to build your G dataflow application into an executable (.exe).
On the
Document
tab, choose the
File type
of the MATLAB file you want to call.
NI recommends that you format MATLAB programs into functions because functions perform better than scripts and offer a clean programming model.
Define the
interface node
that maps to the arguments in the function or variables in the script.
Click
Add interface node.
On the
Item
tab, enter a name for the interface node.
The name will show up in the node icon.
Click
Add parameter.
On the
Item
tab, specify the parameter name, data type, and behavior.
Add more parameters as necessary.
The number of parameters in the interface node must match the number of arguments in the function or the number of variables in the script.
Save the Interface for MATLAB.
Open the VI in which you want to call the MATLAB function or script.
On the diagram palette, click
Project Items»Software
to find the interface node you defined in the Interface for MATLAB.
Drop the interface node on the diagram.
Wire the interface node and complete the diagram.
Run the VI.
The
MATLAB Command Window
automatically launches. Input data passes from the diagram to MATLAB, and data returns from MATLAB to the diagram.
Note
If you have multiple versions of MATLAB installed, by default the Interface for MATLAB invokes the version of MATLAB you most recently installed.