LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run a executable created in Matlab

Can I create a executable in matlab and use it in labview? What if the executable takes in input and outputs data. Can labview handle that?
0 Kudos
Message 1 of 7
(8,174 Views)
You can run an executable from labview using the system exec function under the communication palette. This acts like the command prompt in windows. You will execute your exe just like in the command prompt. As far as inputs and outputs you can't do this with and executable that I know of. I do know that you can create a dll in matlab that will allow inputs and outputs. Once again in LV you can call this dll and place inputs and have outputs using the call library function. Also in LV there is a new simulation toolkit that will allow you to run simulink models from Matlab. Pretty useful actually. Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
Message 2 of 7
(8,173 Views)
BJD1613 wrote in news:506500000005000000246A0100-1079395200000
@exchange.ni.com:

> I do know that you can create a dll in matlab that
> will allow inputs and outputs.

You need the Matlab compiler to do this, and its not a free option. As far
as I know, the Matlab compiler is the only way to generate an executable
from matlab.
0 Kudos
Message 3 of 7
(8,173 Views)
Yes, you can create an executable or a dll from Matlab (assuming you have the compiler) and call them from LabVIEW. As BJD1613 suggested, you can call a Matlab exe using system exec. You can even include limited arguments (for example, a path to a file with other inputs). To get an output from the exe, you'll probably have to do some kludge through the file system (i.e., write a file, and have LV read it). Alternatively, you can complie your Matlab code to a dll. This can be called directly from LV using the call library functions, but you'll need some extra external code to communicate. Matlab uses a custom datatype (mxArray) which is not supported in LV. To communicate, you need to write an additional program that converts standard datatypes to mxArrays and then returns the pointer. Then pass the pointer to the mxArray into the Matlab dll through the call library node. Same thing for outputs, but in the other direction. This does work, but it can be a real headache to get working. I'd probably stick with the exe route unless you can write that external conversion code (the datatype is well documented).

good luck,
Chris
0 Kudos
Message 4 of 7
(8,027 Views)
Hi Chris. I'm glad to have found your entry about using "call library functions" in MATLAB. I'm trying to call a .dll that was created in MATLAB in LabView. As you have explained, I need to write an additional program that converts standard data types. My dll has three inputs (two scalars and one array) and one output (one array).
Do you have some advice or a sample program that describes how this is done? MATLAB offered a dll example on their website (not tailored for LabView) which is not very helpful at all. I figure if I get an easy example to work, I will be able to deal with more complicated calls. Sofar, the "call library function" error I get is 1097.
 
Thanks for your help,
Steffen
 
 
"Alternatively, you can complie your Matlab code to a dll. This can be called directly from LV using the call library functions, but you'll need some extra external code to communicate. Matlab uses a custom datatype (mxArray) which is not supported in LV. To communicate, you need to write an additional program that converts standard datatypes to mxArrays and then returns the pointer. Then pass the pointer to the mxArray into the Matlab dll through the call library node. Same thing for outputs, but in the other direction. This does work, but it can be a real headache to get working. I'd probably stick with the exe route unless you can write that external conversion code (the datatype is well documented)."
0 Kudos
Message 5 of 7
(7,283 Views)

Steffen, sorry for the late reply. I've been out of the office. It makes a difference which version of MATLAB you are using. Prior to 7, it was much easier (still excruciating, but managable). Since 7, both the LabVIEW code and "communication" code has gotten more complicated. If this is an option, I would consider compiling your matlab code in 6.5. Then the task of speaking with the dll from LabVIEW is much more straightforward. I apologize for not providing code; we are evaluating the possibility of commerciallizing this. The process is to create a standard windows dll (let's call it convert.dll) that understands matlab mxarrays. For inputs to the matlab dll, you call the correct function of convert.dll for the data type your are trying to send in (you can use polymorphic vi's in LabVIEW to call the correct function of the convert.dll from a single wrapper polymorphic vi). For example, to send in a double array, you call the polymorphic instance of the convert.vi that knows to call the correct dblarray2mxarray function of convert.dll. The output of this function and the vi is an 4byte pointer to an mxarray. You then pass this pointer into the matlab dll. On the output side, you do the reverse (you can still use use a polymorphic vi here, but you will have to manually select the correct conversion yourself, i.e., mxarray2int).

This may be a little confusing. To try to simplfy a little, you want to have the following:

 - a matlab dll compiled from Matlab 6.5.

 - a standard windows library for converting mxarrays to standard datatypes (and vice versa) convert.dll

 - two polymorphic labview vi's: mxarray2labview.vi & labview2mxarray.vi with enough instances to handle whatever datatypes you are working with.

 - and a labview vi where you will call everything listed here.

I hope this helps a little.

Chris

Message 6 of 7
(7,178 Views)

Hello Chris,

Thanks for your support. It will become crucial for our company to embed MATLAB code in LabVIEW. The MathScript option that LabView offers works for simple code but not for complex MATLAB code (no compatibility). You have mentioned also that you are evaluating the possibility of commerciallizing this. Is this something we could look forward to in the next few months?

In the meantime I try to get an old MATLAB 6.5 version as you have suggested.

Thanks,

Steffen

0 Kudos
Message 7 of 7
(7,165 Views)