Error 1731 Using the Call MATLAB® Function in LabVIEW 

Updated Oct 25, 2023

Reported In

Software

  • LabVIEW

Issue Details

I am getting Error 1731 when trying to run a program from The MathWorks, Inc. MATLAB® software (MATLAB) in LabVIEW using the Call MATLAB Function. 
image.png
Error 1731 occurred at Call MATLAB Function in <VI name>

Check that the number of return values and their types from the function, matches the return type specified in the VI.
Source: <MATLAB File Path>
Funtion Name: <MATLAB Function>
MATLAB call returned the following error: Expected cluster type for function returning multiple return values.

Solution

This error is caused when the data structure MATLAB tries to return does not match the structure specified in LabVIEW. As detailed in the Call MATLAB Function documentation, you must wire a constant or control matching the data type of the top level MATLAB function return type to return type.

For example, if the MATLAB function returns an array of doubles, you must wire an array of doubles constant or control to return type. If the MATLAB function returns multiple values, wire a cluster with elements that correspond to the MATLAB function return values. The name and data types and order of the cluster elements must match the MATLAB function return values. For example, if the MATLAB function returns a numeric, a Boolean array, and a string, you must wire return type to a cluster containing controls or constants of numeric, Boolean array, and string data types in that order. Cluster element names must be unique and not empty. If the MATLAB function does not return any value, leave return type unwired.

The following is an example of a VI using the Call MATLAB Function to run the initialize.m program. It has been configured to process three variables (R, L, hbar) returned from MATLAB.
image.png

Additional Information

The Call MATLAB Function supports the following data types:

  • Numerics
  • Arrays, including multi-dimensional arrays
  • Strings
  • Clusters
  • Booleans