MATLAB® Script Returning Single Value for Array Output Using LabVIEW MATLAB® Script Node

Updated Jun 6, 2023

Reported In

Software

  • LabVIEW
  • MATLAB

Other

  • The Mathworks, Inc. MATLAB® Software

Issue Details

I'm using a MATLAB® Script Node to run MATLAB® code directly in my LabVIEW VI. When I try to call a function which returns an array, such as a Hanning Window, in my MATLAB® code, only a single value is returned instead of the expected array of the size I specify. Why is this behavior occurring, and how can I resolve it?

Solution

This behavior can occur if MATLAB® returns array data to LabVIEW in an orientation that LabVIEW is not expecting, such as returning a 1D row array when a 1D column array is expected or vice versa. This results in only the first value being entered in the return array in LabVIEW.

In order to prevent this behavior from impacting your code's performance, you'll need to change the return value for your operation to a 2D array instead of a 1D array and transpose the results to the orientation expected by the rest of your code. This way, the results of your array-generating operation will be properly captured when returned to LabVIEW, and can be manipulated to match what the rest of your code is expecting.

Example of edited MATLAB Code Snippet which will allow you to properly write array values into LabVIEW.

Additional Information

This error does not affect all MATLAB® functions and operations, so you may not need to edit your code when using an array-returning function. If you see the behavior noted in this article, then you will need to edit your MATLAB® code to write to a 2D array and transpose the result.