Error 1050 on Second Execution of My MATLAB® Script Node

Updated Sep 5, 2023

Reported In

Software

  • LabVIEW

Issue Details

I use the LabVIEW MATLAB script node to interact with The MathWorks, Inc. MATLAB® software: My code works fine when it runs once. But it will fail on the second run with Error 1050

Error occurred while executing script. Error message from server: ??? Subscripted assignment dimension mismatch.

To run it again, I have to clear all the variables ('clear all' command in MATLAB window), then run the VI. I like to be able to run the VI continuously.

Solution

You are passing arrays to your MATLAB® node and then use these to initialize output vectors. These get initialized to a specific length on the first run of the script. MATLAB stores these definitions internally. Running the script a second time passing arrays of a different size causes the "dimension mismatch" error in the screenshot above, as the new arrays do not fit into the previously initialized vectors.

There are several possible solutions to this issue:
  • Pass arrays of the same size to your MATLAB script node each time.
  • Store your data in elements of a Cell Array instead of in a vector inside your MATLAB code.
  • Initialize your vectors manually to an adequate length so they can hold the biggest array you will pass to it. Pass an extra argument to know the size of the payload data.