ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call MATLAB Function

Solved!
Go to solution

I was keen to try the new Call MATLAB Function node in LabVIEW 2021 and learned that if you make changes to the m-file, you must kill the MATLAB process before running the VI again.  

 

For example, put the attached VI and M-file in the same directory and run the VI.  We can see that B = 1 - A.  Screen Shot 2021-08-23 at 00.42.10.png

Change line 3 of the M-file to B = 1 + A, and we still get 

Screen Shot 2021-08-23 at 00.47.50.png

But if we kill the MATLAB process 

Screen Shot 2021-08-23 at 00.49.21.png

and re-run the VI, we now have the expected behavior of B = 1 + A.  

Screen Shot 2021-08-23 at 00.50.32.png

Is this the intended behavior?  Either way I'm posting here so others know what to expect.   

0 Kudos
Message 1 of 7
(5,297 Views)

Did you restart the VI after the change was made or went straight for the kill?

0 Kudos
Message 2 of 7
(5,295 Views)

I just checked - closing the VI doesn't change this behavior. 

Quitting LabVIEW, however, has the same effect as killing the MATLAB process.

0 Kudos
Message 3 of 7
(5,284 Views)
Solution
Accepted by topic author resono-mp3

It's a known issue, see https://www.ni.com/en-gb/support/documentation/bugs/21/labview-2021-known-issues.html

 

It claims it's resolved in LabVIEW 2022. Not sure what to make of that...


GCentral
Message 4 of 7
(5,281 Views)

I have built an executable in LV2022Q3 calling an m file. But after closing the reference, the matlab process remains active. Only when I terminate the app, the matlab process terminates as well.

I ended up calling a second m file that kills the matlab process! Obviously an error is returned in Labview, but that can be simply ignored.

 

aartjan_0-1663686984939.png

 

I also learned that if you get an error when calling a matlab function, chances are that you cannot rerun the routine without getting the same error over and over again. You will need to kill the matlab process first.

 

0 Kudos
Message 5 of 7
(4,717 Views)

kill script:

function exit_()
    feature getpid;
    cmd = ['!taskkill /F /PID ' num2str(ans)];
    eval(cmd)
end
0 Kudos
Message 6 of 7
(4,705 Views)

Shame btw that the call matlab function won't also accept string input.

0 Kudos
Message 7 of 7
(4,703 Views)