LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab code convert into the labview??

how can i plug the matlab code into the labview?

As i need to deal with the Bspline nonlinear water tanks now..No idea how to set up the labview for that

i wonder anycode in labview can make my life go easier

Message 1 of 6
(16,998 Views)

Hi little77,

 

Good Morning and I hope your well today.

 

Thanks for your post.

 

You have several options when considering trying to use matlab script (m script) within LabVIEW.

 

Here is a good introduction,

 

Options for Working with NI LabVIEW; The MathWorks, Inc. MATLAB® Software; and M-File Scripts

http://www.ni.com/analysis/matlab.htm

 

Firstly, LabVIEW has support of  Mathscript Node and the Matlab Node.

 

Mathscript:

(Programs>>Structures...)

Support for this is included in Full, Professional and Development.

See Image below. 

 

NI LabVIEW MathScript

http://www.ni.com/labview/mathscript.htm

More information on Mathscript.

 

Notes:

Mathscript supports a large set of functions within mathscript.

LabVIEW also has the mathscript editor window - tools>> Mathscript Window.. which looks similar to matlab with an output window, variables, command window and graphical vsections. See image below. 

 

Performance Considerations:

LabVIEW 8.5 and 8.6 have had major performance improvements compared with previous versions of LabVIEW.

You shouldn't simple place your entire application into this mathscript node. You should consider replacing some aspects of your code (script) with LabVIEW functions to help improve performance. This is because the mathscript can't be run in parallel - which is a major strength of LabVIEW. If you wish to keep your script, then I would advise breaking down or chunking your script into several nodes to all the script nodes to execute in parallel.

 

Matlab Node:

MATLAB Script Node (Windows, Not in Base Package) 

Calls the MATLAB® software to execute scripts. You must have a licensed copy of the MATLAB software version 6.5 or later installed on your computer to use MATLAB script nodes because the script nodes invoke the MATLAB software script server to execute scripts written in the MATLAB language syntax. Because LabVIEW uses ActiveX technology to implement MATLAB script nodes, they are available only on Windows.

One of the slowest performance aspects of the node are loops. So try to reduce the number of iterations in the script where at all possible. 

 

So to me it would seem just placing the section of code for your application which you've expressed in mathscript into the node would be fine. As long as you limit the amount of code within the node, and attempt to replace as much as possible (that doesn't need to be in the script node) into LabVIEW functions then it would seem your suggestion of using your script with LabVIEW is great! Exactly what its designed for.

 

Please let me know if you have any questions on the information I have given you, If you could also give me more information about Bspline water tanks maybe I could help further.. or someone on the forum may have done this before.

 

I also wanted to add*

That if you look in the NI Example Finder (Help>>Find Examples..) and search Mathscript there are several shipped examples, including Fundamentals.

 

Hope this helps,

Message Edited by Hillman on 04-01-2009 09:39 AM
Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
Download All
Message 2 of 6
(16,981 Views)

hi Hillman,

 

I just saw you post. It is helpful for me, as I do have a application which need use the Matlab Code in the LabVIEW.

 

And I have a further question. From your post, I know that the mathscript can support most functions in the matlab. So my question is that whether it can support some special functions, like the Genetic Algorithm ga() and Neural Network function. And is there some different with the use in matlab?

 

Any reply and comments are apprreciated.

 

Sample

0 Kudos
Message 3 of 6
(12,725 Views)

All of the functions that MathScript has are in the documentation. If you do not have MathScript, but are considering it, then you can review the documentation here: http://digital.ni.com/manuals.nsf/websearch/C32F78ED8945D622862578CC00689FD6

 

The function you mention sounds like it's from a special toolkit. MathScript would not have that.

0 Kudos
Message 4 of 6
(12,720 Views)

Thanks a lot for answers.

 

By now, I think I have to use matlab script node to run the matlab code, as I have to use the neural network function of matlab.

 

Do you think it is time-consuming in this way, ask the third-part software to compile and execute my m-file scripts?

 

Sample.

0 Kudos
Message 5 of 6
(12,695 Views)

Do you mean time-consuming in terms of its speed? Well, the Matlab script node works by communicating with the Matlab ActiveX server, so it's not going to be as fast as running the script natively. How much of an impact that will be is impossible to say - you will need to test it out.

 

Is it better to compile the script into a DLL? Probably not. If you compile it into a DLL you will need to use Call Library Function Node to call the DLL. You also have to make sure that the DLL does not use complicated datatypes. You have to keep in mind that the Call Library Function Node is designed to call C DLLs. Thus, it's not really designed to handle complicated datatypes. If you do use them then you will need a wrapper DLL between the Matlab DLL and LabVIEW.

 

Also keep in mind that the target machine will require a Matlab license if you use the Matlab script node.

0 Kudos
Message 6 of 6
(12,678 Views)