Skip to main content
ubuntuask.com

Back to all posts

How to Call A Matlab Function From Labview?

Published on
6 min read
How to Call A Matlab Function From Labview? image

Best Software Integration Tools to Buy in October 2025

1 Software Tools

Software Tools

BUY & SAVE
$86.57
Software Tools
2 Moho Pro 13.5 | The all-in-one animation tool for professionals and digital artists | Software for PC and Mac OS

Moho Pro 13.5 | The all-in-one animation tool for professionals and digital artists | Software for PC and Mac OS

  • EFFORTLESSLY IMPORT PSD FILES FOR SEAMLESS ANIMATION INTEGRATION.
  • UNMATCHED RIGGING SYSTEM WITH SMART BONES FOR INTUITIVE CUSTOMIZATION.
  • CREATE DYNAMIC 3D EFFECTS USING SIMPLE 2D MESH MANIPULATION.
BUY & SAVE
$99.00
Moho Pro 13.5 | The all-in-one animation tool for professionals and digital artists | Software for PC and Mac OS
3 Software Project Management For Dummies

Software Project Management For Dummies

BUY & SAVE
$20.88 $39.99
Save 48%
Software Project Management For Dummies
4 Continuous Integration: Improving Software Quality and Reducing Risk

Continuous Integration: Improving Software Quality and Reducing Risk

BUY & SAVE
$61.88
Continuous Integration: Improving Software Quality and Reducing Risk
5 Avid Pro Tools Ultimate Perpetual Recording Software (Boxed)

Avid Pro Tools Ultimate Perpetual Recording Software (Boxed)

  • MASSIVE MIXING: 2,048 AUDIO TRACKS & 512 INSTRUMENT TRACKS!
  • RECORD 256 AUDIO SOURCES AT ONCE FOR UNPARALLELED CREATIVITY!
  • EXPLORE 120+ VIRTUAL INSTRUMENTS & ADVANCED POST-PRODUCTION TOOLS!
BUY & SAVE
$1,499.00
Avid Pro Tools Ultimate Perpetual Recording Software (Boxed)
6 Mastering GitHub Actions: Advance your automation skills with the latest techniques for software integration and deployment

Mastering GitHub Actions: Advance your automation skills with the latest techniques for software integration and deployment

BUY & SAVE
$49.99
Mastering GitHub Actions: Advance your automation skills with the latest techniques for software integration and deployment
7 Jenkins: The Definitive Guide: Continuous Integration for the Masses

Jenkins: The Definitive Guide: Continuous Integration for the Masses

  • AFFORDABLE PRICES: QUALITY BOOKS AT A FRACTION OF RETAIL COST.
  • ECO-FRIENDLY CHOICE: PROMOTE RECYCLING AND SUSTAINABILITY WITH USED BOOKS.
  • UNIQUE FINDS: DISCOVER RARE TITLES AND EDITIONS NOT FOUND ELSEWHERE.
BUY & SAVE
$20.36 $44.99
Save 55%
Jenkins: The Definitive Guide: Continuous Integration for the Masses
8 Learning Continuous Integration with Jenkins: An end-to-end guide to creating operational, secure, resilient, and cost-effective CI/CD processes

Learning Continuous Integration with Jenkins: An end-to-end guide to creating operational, secure, resilient, and cost-effective CI/CD processes

BUY & SAVE
$42.49 $49.99
Save 15%
Learning Continuous Integration with Jenkins: An end-to-end guide to creating operational, secure, resilient, and cost-effective CI/CD processes
9 Building Integrations with MuleSoft: Integrating Systems and Unifying Data in the Enterprise

Building Integrations with MuleSoft: Integrating Systems and Unifying Data in the Enterprise

BUY & SAVE
$51.99 $59.99
Save 13%
Building Integrations with MuleSoft: Integrating Systems and Unifying Data in the Enterprise
+
ONE MORE?

To call a MATLAB function from LabVIEW, you can use the following steps:

  1. Launch LabVIEW and create a new VI.
  2. Open the Block Diagram by double-clicking on it.
  3. Locate the MATLAB script node on the Functions palette. It is usually found under Connectors»External Evaluation.
  4. Drag and drop the MATLAB script node onto the Block Diagram.
  5. Right-click on the MATLAB script node and select Configure.
  6. In the Configuration dialog, click on the "New" button under the MATLAB script path.
  7. Browse and select the MATLAB function you want to call from LabVIEW.
  8. Click OK to close the Configuration dialog.
  9. Wire the necessary inputs and outputs to the MATLAB script node, just like you would with any other LabVIEW function.
  10. Save the VI and run it to call the MATLAB function.

By following these steps, you can easily integrate MATLAB functionality into your LabVIEW applications and take advantage of MATLAB's powerful computational capabilities.

What is the procedure for handling complex control flow in a Matlab function called from LabVIEW?

When handling complex control flow in a MATLAB function called from LabVIEW, you can follow these steps:

  1. Define the MATLAB function: Write the MATLAB function with the desired complex control flow logic using conditional statements (if-else, switch, etc.), loops (for, while), or other control flow constructs. Make sure the function takes input arguments and returns output values as needed.
  2. Create a LabVIEW VI: Open LabVIEW and create a VI that will call the MATLAB function. The VI should have appropriate input controls and output indicators for passing data to and from the MATLAB function.
  3. Import the MATLAB code: Use the "MATLAB Script" or "MATLAB Node" in LabVIEW to import the MATLAB code into the VI. You can directly copy-paste the MATLAB code or use the import functionality provided by LabVIEW.
  4. Map input data: Connect the input controls of the LabVIEW VI to the appropriate inputs of the MATLAB function. This allows you to pass data to the MATLAB function from LabVIEW.
  5. Map output data: Connect the outputs of the MATLAB function to the output indicators of the LabVIEW VI. This allows you to retrieve the calculated results from the MATLAB function in LabVIEW.
  6. Handle complex control flow: In the LabVIEW VI, you can incorporate conditional structures (Case Structures, Select Blocks) or loops (For Loops, While Loops) to control the flow of execution and handle any additional complex control flow requirements specific to LabVIEW.
  7. Execute the VI: Run the LabVIEW VI to execute the MATLAB function and observe the results.

By following these steps, you can effectively handle complex control flow in a MATLAB function called from LabVIEW.

How to debug Matlab code called from LabVIEW?

Debugging MATLAB code called from LabVIEW can be done using a combination of techniques in both platforms. Here are the steps to debug MATLAB code called from LabVIEW:

  1. Open the LabVIEW project or VI that calls the MATLAB code.
  2. Place a breakpoint in the VI at the point where the MATLAB code is being called.
  3. Run the LabVIEW VI in Debug mode by clicking the Run button with the Debug icon or using the Ctrl+R keyboard shortcut.
  4. When LabVIEW hits the breakpoint, make sure the MATLAB code nodes are visible in the block diagram.
  5. Right-click on the MATLAB code node and select "Disconnect from MATLAB" to pause execution before the MATLAB code is executed.
  6. Open MATLAB from the Start menu or taskbar. Ensure that the desired MATLAB workspace and necessary variables are set up.
  7. In MATLAB, open the .m file or script that is being called from LabVIEW.
  8. Set a breakpoint in MATLAB at the desired location where you want to start debugging the code.
  9. Go back to the LabVIEW environment and right-click on the MATLAB code node again, but this time select "Connect to MATLAB."
  10. Now, executing the LabVIEW VI will trigger the MATLAB script, and MATLAB will pause at the designated breakpoint.
  11. Debug the MATLAB code within the MATLAB environment using various techniques such as stepping through the code, inspecting variables, and evaluating expressions.
  12. After debugging the MATLAB code, resume execution in MATLAB by pressing the "Continue" button.
  13. Go back to the LabVIEW environment, where MATLAB will continue running from the paused state.
  14. Use the LabVIEW debugging tools to monitor the data flow between LabVIEW and MATLAB, inspect variables, and verify the code's execution.
  15. Repeat steps 10-14 to continue debugging MATLAB code called from LabVIEW as needed.

By following these steps, you can effectively debug MATLAB code called from LabVIEW and identify and rectify any issues or errors in the code.

How to pass arrays from LabVIEW to a Matlab function?

To pass arrays from LabVIEW to a MATLAB function, you can follow these steps:

  1. Install the LabVIEW MathScript RT Module if it is not installed on your computer. This module allows you to interact with MATLAB functions directly from LabVIEW.
  2. Create a LabVIEW VI and build the logic for generating or obtaining the array data you want to pass to MATLAB.
  3. Convert the LabVIEW array to a MATLAB array using a LabVIEW MathScript Node. The MathScript Node allows you to write MATLAB code directly within LabVIEW.
  4. Use the "Output" terminal of the MathScript Node to pass the MATLAB array to a MATLAB script or function.
  5. Create a MATLAB script or function where you can receive the array parameter from LabVIEW and perform the desired calculations or operations.
  6. Execute the MATLAB script or function using the MATLAB Script Node in LabVIEW.
  7. Receive the results back from MATLAB to LabVIEW, if necessary, by converting the MATLAB output array to a LabVIEW array using another MathScript Node.
  8. Process the MATLAB output array within LabVIEW, or display or use the results as desired.

By following these steps, you'll be able to pass arrays from LabVIEW to MATLAB functions and perform computations or operations using MATLAB's capabilities within the LabVIEW environment.