09-22-2010 11:22 AM
I have a matlab .m file that runs a function. In my Labwindows software, I want to be able to run this function. Is this possible? Thanks.
09-23-2010 08:18 AM - edited 09-23-2010 08:19 AM
It has been a while since I have done this but there are a number of different ways to run .m files from cvi.
1) If matlab is installed on the target machine, register it as a activex server and use the matlab server interface to directly run the matlab file.
2) Matlab at one time had a toolkit that allowed the creation of a dll from a .m file or files. This allowed the routines in the .m to be called from cvi just like any other function. The toolkit included a matlab runtime library that was loaded on each target machine.
3) Matlab at one time had a toolkit that cross-compiled .m files to C code. Again with the correct runtime library this allowed .m files to be incorporated directly into a cvi application.
09-23-2010 03:10 PM
Here is an example to try:
http://zone.ni.com/devzone/cda/epd/p/id/2994
Thanks,
09-23-2010 03:11 PM
There is also an example in the Example Finder called demoforMATLABinterface.cws , just search for MATLAB
05-25-2011 06:30 AM
Hello,
I tried second idea and Matlab produces a dll and lib file which I used in LabWindows but it dont recognize the lib format. If You did it, could you tell me how exactly? I used this commands:
mcc -W lib:libfoo -T link:lib foo.m bar.m
and
mcc -B csharedlib:libmatrix addmatrix.m multiplymatrix.m eigmatrix.m -v
and the dll and lib files are created but LabWindows dont recognize the lib file.
I have got LabWindows 8.5, Matlab 7.7.0 (R2008b).
05-25-2011 10:26 AM
Unfortunately, I did not end up integrating my Matlab script into my Labwindows program. I just decided to simplify everything and rewrite the script in Labwindows so I wouldn't have to deal with extra stuff in dealing with Matlab. Sorry.
05-26-2011 02:34 PM
I used Real-Time Workshop and compiled the m file and get the C code but every thing must be static there. I used a command:
emlc -T rtw aproxLSM.m -v
Matlab generates an embedded code in C with headers and everything may be included in LabWindows.
I cant use functions from dll in LabWindows becouse they process a specific Matlab arrays (mxArray) wchich can be set only by Matlab functions.
05-26-2011 05:58 PM
Hi Kamkon,
Have you had a chance to look into the example posted by Anna? I've come across discussion forums regarding how to use MATLAB dlls in LabWindows CVI. They are listed below. I hope this is of some help to you.
http://forums.ni.com/t5/LabWindows-CVI/How-to-use-a-Matlab-DLL-in-CVI/m-p/548105?requireLogin=False
Creating a MATLAB dll is somewhat outside the scope of our suppot. However, I have found a third party link on this topic. Hopefully, it will point you in the right direction.
http://www.mathworks.com/support/solutions/en/data/1-18CBI/index.html?solution=1-18CBI
Regards.
Josh L.
05-29-2011 06:48 AM
Thank you.
I will try this approach mentioned in the link.
12-19-2013 09:17 PM
Of all the options, Which can run .m function in a PC without matlab preinstalled?
Thats the one I want to try, to generate heavy .wav files (an easy matlab function) from CVI, making the installer lighter.