LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MATLAB Script Node Error 1048 and passing values - Why?

I'm developing code and using two MATLAB script nodes side by side. I'm getting the 1048 error in passing variables between the two functions. I found I could reduce how frequently I get the error by adding a wait block between the two MATLAB scripts.

 

I read the help page: http://digital.ni.com/public.nsf/allkb/3770DDA4593BF5D6862567D0007A31E6 - but my code doesn't use reserve words, doesn't have a clear all, and the variable names have been changed in the input and output of the functions.

 

I tried playing around with removing the external scripts (updateSavedMosaic.m and updateLiveMosaic.m) from each of the script nodes (if blocks). I don't get the error when I don't call updateSavedMosaic.m; however, the variables aren't transfered properly -- im0_ becomes empty even though im1_ is not.

 

Any thoughts on what could be going wrong here?

 

Here's a screenshot of my vi.  I was also unable to post the two matlab files - so they are also embedded within this link.

 

Thanks,

Kristen

 

 

 

0 Kudos
Message 1 of 8
(2,895 Views)

Is there a reason why you can't use a single MATLAB® script node? I think that would avoid the error in this situation.

 

The node is actually making activeX calls to automate your .m code in MATLAB®. There is going to be a lot more overhead involved with using two nodes rather than one. It looks like everything executes sequentially in your code. Node 1 waits for an input from node two, etc.  

 

Alternatively you could try a method similar to pipelining, writing values to a shift register or feedback node between the two script nodes so that a value is always available, rather than waiting on those activeX calls. 

 

Let me know your thoughts, 

 

Zach

 

MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 2 of 8
(2,852 Views)

Is there a reason why you can't use a single MATLAB® script node? I think that would avoid the error in this situation.

>> I made this vi as a test, but eventually the logic will be a bit different. Both scripts will be in a for loop. The first script will execute on each iteration of the loop adding a new image to the mosaic I'm trying to create. The second script will execute after the first script during iterations where the user indicates that the second script should be run. There will likely be several seconds (~10) between the execution of the two scripts. 

 

Alternatively you could try a method similar to pipelining, writing values to a shift register or feedback node between the two script nodes so that a value is always available, rather than waiting on those activeX calls. 

>>  Will this ensure that the correct value gets passed? I'm assuming this might make the error go away, but the correct value may not be passed if the activeX call is not finished. 

0 Kudos
Message 3 of 8
(2,839 Views)

It still sounds very possible to implement in one node. You could write an if statement around the second section of code in .m script based off of a input from the LabVIEW VI. If that input is true, else skip over it. That way the data will only be passed inside the single node rather than pulled by again by a second node. 

 

Using a pipelining method would add an iteration of latency to your code for each shift register/feedback node in your code. In your case if the user decided to run the second node it would need to execute on the next iteration of the For loop rather than the current one. (could be achieved with another shift register/feedback node on the user input)

 

 

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 4 of 8
(2,835 Views)

I think the single node approach should work. It's going to take a bit of refactoring of my code, though.

 

I'm curious to know why this works, though. In the single node case, I'll still be calling some matlab node just as frequently (e.g. calling node A every time instead of calling node A, then B, then A...). Why doesn't this cause the same problem, since new data would need to be pulled each time? 

 

Thanks,

Kristen

0 Kudos
Message 5 of 8
(2,830 Views)

I'm don't know exactly how the MATLAB Script node works behind the scenes, but I do know its based off of ActiveX calls.  That means that each time there is a MATLAB Script node, it is opening an ActiveX connection to MATLAB, transferring the .m code and any inputs, waiting for that to execute then transferring that data back to LabVIEW and closing the connection. None of the data from one node remains in MATLAB to be pulled again, all of those variables, etc have to be set up and cleared each time the script is run. Running two nodes is completing that process twice, and in your case its only doing it to pass information from some .m code to other .m code. Instead of going through all of that overhead twice, bringing that data back from MATLAB passing it to LabVIEW and passing it back to MATLAB, the entirety of that data could set up and contained within one call to MATLAB to be used by the second section of code when desired. I could be wrong, but I bet the minor overhead of skipping over the extra code each iteration is likely going to be less across the 10 iterations than the additional overhead of the second node.

 

Does that answer your question?   

 

Zach

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 6 of 8
(2,822 Views)

The single node approach still didn't work. I think it's somehow related to how much data is being passed into the node. When I reduce the input to just a single integer in each case, I do not get the error. 

 

Is there some where you can point me to that discusses proper useage/recommended useage for matlab script nodes? It would be helpful for future development. 

 

Kristen

0 Kudos
Message 7 of 8
(2,809 Views)

Are you still getting the same error 1048? 

 

You shouldn't be passing any additional data into the node as you were before. The second node had the same inputs as the first.

As per my understanding you were only receiving the error on the second node. Did I assume that incorrectly? 

 

The LabVIEW help describes the node fairly well: supported data types, walking through a simple example

 

You mentioned that it works with a single integer, have you tried sending different combinations of your inputs into the node to see if there is a specific input that throws the error? 

Could you also try converting your datatypes before wiring them into the node, so that they don't have to be coerced? 

 

Thanks, 

 

Zach

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 8 of 8
(2,803 Views)