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
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
Firstly, LabVIEW has support of Mathscript Node and the Matlab Node.
Support for this is included in Full, Professional and Development.
See Image below.
NI LabVIEW MathScript
More information on Mathscript.
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.
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 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,
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.
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.
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?
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.