Pat O Posted September 22, 2009 Report Share Posted September 22, 2009 I've been using the Matlab script node and always noticed something funny about how it handles scripts (.m files) that I had saved. I finally figured out yesterday what it was. If you edit the script in matlab and save it, LabVIEW won't see the changes. For example: Create a file called test.m which just has: a=a+1; Next create a vi that has a Matlab Script Node with inputs and and outputs of "a" attached to a control and indicator respectively which only contains a script node with the code: cd <whatever directory test.m was saved to>; test If you run this code with the control set to 0, the indicator will read 1 as expected. Now, if you go edit the file test.m to a=a+2; (without closing your vi) and then rerun the vi, it will still give you 1, not 2. If you close the vi, then reopen it, it will give you 2 as expected. Is there a way to generate new execution code for LabVIEW without closing the vi and reopening it. Quote Link to comment
redneckjedi Posted September 22, 2009 Report Share Posted September 22, 2009 I've been using the Matlab script node and always noticed something funny about how it handles scripts (.m files) that I had saved. I finally figured out yesterday what it was. If you edit the script in matlab and save it, LabVIEW won't see the changes. For example: Create a file called test.m which just has: a=a+1; Next create a vi that has a Matlab Script Node with inputs and and outputs of "a" attached to a control and indicator respectively which only contains a script node with the code: cd <whatever directory test.m was saved to>; test If you run this code with the control set to 0, the indicator will read 1 as expected. Now, if you go edit the file test.m to a=a+2; (without closing your vi) and then rerun the vi, it will still give you 1, not 2. If you close the vi, then reopen it, it will give you 2 as expected. Is there a way to generate new execution code for LabVIEW without closing the vi and reopening it. This is probably occurring because you have two instances of MATLAB open: the one you are editing, and the one LabVIEW is using to communicate with MATLAB and run the .m file. Try this: 1) Start with all applications closed. 2) Open the VI that has the Matlab Script Node and run it. You should notice a MATLAB Command Window in your taskbar as well. 3) Instead of double clicking test.m to open it, or opening MATLAB yourself to edit it, switch to the MATLAB Command Window and type 'open test.m' and hit enter. You should get test.m up in an editor. 4) Edit test.m to say a=a+2 as you mentioned above and save it. 5) Run the VI again. Because you edited the .m file in the same instance that will execute it, MATLAB knows that it needs to recompile it before it runs it. Apparently MATLAB does some caching when it compiles scripts into runnable code, and multiple instances of MATLAB don't talk to each other about which cached versions have been invalidated and should be recompiled. Editing in the same instance that will be doing the execution should fix that for you. I hope that helps. 2 Quote Link to comment
Pat O Posted September 22, 2009 Author Report Share Posted September 22, 2009 Amazing! Thanks so much! Quote Link to comment
Pat O Posted April 13, 2011 Author Report Share Posted April 13, 2011 Two years later...I found another way to handle this which is to put a clear functions command in a MATLAB Script Node at the start of the VI. This will force a recompile of the externally-edited .m file. 2 Quote Link to comment
bjustice Posted September 3, 2018 Report Share Posted September 3, 2018 7 years later, this information helped me! Thanks for coming back to post Quote Link to comment
X___ Posted September 14, 2022 Report Share Posted September 14, 2022 13 years later, this is still not documented in LabVIEW. And since in the meantime the Matlab node has also changed, you now need to reate a little "ClearAll.m" Matlab helper script that contains: function ClearAll() clear functions end and call it before your node of interest when developing... Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.