LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a SubVI in MatLab script?

Can you call a subVI in MatLab script node, or does the SubVI 'node' always have to be used?

If this can be done, how is it done - can 'load' be used followed by the subVI address on the computer? 

 

Any help would be much appreciated!

Thank you in advance,

Dani 🙂

0 Kudos
Message 1 of 14
(3,591 Views)

No, you cannot call a subVI from a Matlab script node. Calling the Matlab script node accesses the Matlab ActiveX server, at which point Matlab essentially takes over.

 

What exactly are you trying to do?

0 Kudos
Message 2 of 14
(3,582 Views)

Hi, thanks for your reply! 

Essentially, I'm rewriting a current program and replacing the current operations done in LabVIEW with MatLab script. So for example in the attached file the VI runs a true/false node, and for true it runs one SubVI, and for false it runs an alternative. The true/false is an easy thing to rewrite in MatLab, however I wasn't sure if or how to call the different subVIs. I think the only way around this may be to write the SubVIs as .m files and call them through the MatLab node?

 

Thanks,

Dani Smiley Happy 

0 Kudos
Message 3 of 14
(3,575 Views)

Why are you rewriting in Matlab when you already have it in LabVIEW?

0 Kudos
Message 4 of 14
(3,568 Views)

As that is the task I have been set! To convert the mechanics of the labview programme into MatLab script (as this is what our students are taught) but using the LabVIEW front panels for their design and user interface. 

 

Okay, so the subVI's can't be solved, in which case I have programmed them up and will call them as .m files I think. I am experiencing problems in the MatLab script node now, for some reason my script doesn't recognise the input variables coming from LabVIEW... any ideas how I would make it understand that this is user input?

 

Thanks again for your help! 

 

DaniSmiley Happy

0 Kudos
Message 5 of 14
(3,548 Views)

Oh and just to explain the attached picture - basically the user inputs their gas selection from gases 1 to 5 (entered on the front panel) and then inputs the desired coefficient (from numbers 1 - 6). 

 

This should then use the correct input of data and read the coefficient from the correct matrix at the correct row. 

Any guidance would be much appreciated!!

 

Thanks,

Dani

Smiley Happy

0 Kudos
Message 6 of 14
(3,546 Views)

Do not use the Array to Matrix conversion function. It is pointless in this case since your array is 1D to begin with. Set the datatype of CO2, etc to 1D Array of Real. If you must have them as 2D arrays, then use the Build Array function rather than the Array to Matrix. The matrix datatype is a specific LabVIEW datatype, not a generic datatype.

 

You are redefining Gasselection with the "global" line. You've already defined it by having it as an input to the script node.

 

Also, Matlab array indexing starts at 1, not zero. Thus, the line "Coefficient = CO2(0, coefficientselection)" would be invalid.

 

Why are "Gas" and "Coefficient" floating points? They're indexes into arrays, thus should be I32.

0 Kudos
Message 7 of 14
(3,536 Views)

Thank you so much for that - I have added in your corrections but it still doesn't display the value in the output Smiley Indifferent 

 

I have attached what it looks like now - realised the selection was also the wrong way round for CO2 etc.! Do I need to be using the MathScript editor window with this even though it is in a MatLab script node?

 

Thanks so much, I've spent many hours getting more and more frustrated with this, so any ideas and corrections you have are very very much appreciated!

 

Dani

 

0 Kudos
Message 8 of 14
(3,533 Views)

"Coefficient = CO2(1, coefficientselection)" is actually performing redundant indexing within Matlab since CO2 is a 1D array.  What is the value of the Coefficient control?

 

You can't use the MathScript editor window. MathScript and Matlab are two different things.

 

Please attach your code if you still have further problems.

0 Kudos
Message 9 of 14
(3,520 Views)

Thanks, I don't really understand what 'redundant indexing' is, as I'm unsure how to change the code! I've attached the coefficient table and a picture of the script if you could take a look that'd be great! I've commented out most of the code to see if I can just get one value out first of all. I'm unsure where to go from here - I can't figure out how to attach the VI by itself, sorry!

 

Thanks so much,

Dani

 

Download All
0 Kudos
Message 10 of 14
(3,516 Views)