If you use NI software to automate tests and would like to leverage analysis and algorithms written in MATLAB in those tests, one solution is to use MATLAB Coder to generate a C DLL that can be called in LabVIEW. MATLAB Coder is an add-on toolbox for MATLAB that generates readable and portable C and C++ code from MATLAB code. MATLAB Coder supports functions from base MATLAB as well as those from other MATLAB Toolboxes.
Following this tutorial will create DLLs and wrapper VIs that can be used in 64-bit versions of NI software. If you are compiling the DLL for use in a 32-bit version of NI software, like LabVIEW 32-bit, TestStand, or VeriStand, and are on a 64-bit operating system, please follow these instructions to learn how to compile a 32-bit DLL with MATLAB Coder: Build 32-bit DLL on 64-bit Windows® Platform Using MSVC Toolchain.
This tutorial was created using LabVIEW 2020 64-bit and MATLAB and MATLAB Coder 2020a.
To generate a DLL with the MATLAB Coder add-on, follow the steps in the MathWorks tutorial: Generate C Code by Using the MATLAB Coder App and the equivalent Generate C Code at the Command Line.
Once you have generated the DLL using MATLAB Coder, use the Import Shared Library Wizard to create a library of LabVIEW VIs. The process is shown below with a DLL created with MATLAB Coder and the Euclidean DLL generated in the MathWorks tutorial.
You can now use the VIs from this library wherever the MATLAB functions are needed.
MATLAB® and MATLAB Coder™ are trademarks or registered trademarks of The MathWorks, Inc.
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.