Jump to content

Matlab Script Node doesn't update when .m file edited externally


Recommended Posts

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.

Link to comment

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.

  • Like 2
Link to comment
  • 1 year later...
  • 7 years later...
  • 4 years later...

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...
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.