LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling matlab MEX routine from LabVIEW

Hi,

Is it possible to directly interface Matlab MEX routine from LabVIEW. Mex files are matlab binary code DLLs together with some sort of meta data file, that Matlab can call as if they were Matlab m-files.
--
Tomi Maila
0 Kudos
Message 1 of 6
(4,250 Views)
Tomi,
please have a look on the following discussion forum entry.

Thanks,
ThSa

0 Kudos
Message 2 of 6
(4,246 Views)
Hi,

I think ThSa the thread you referred to is talking about different thing. I do not want to access code written in matlab or matlab data files. I need to access a matlab file import utility that is written in C and compiled to matlab DLL + mex. The DLL contains only one function and the mex file contains probably some metadata. I want to access this DLL directly from LabVIEW if that is possible, without compiling an other DLL that can access this DLL that can access a third DLL that can read a file of specific type.

Tomi
--
Tomi Maila
0 Kudos
Message 3 of 6
(4,242 Views)

I don't think this thread was ever answered.

 

I have a Matlab compiled DLL (MEX) which I want to access from LabVIEW.  Is this possible?

0 Kudos
Message 4 of 6
(3,852 Views)

Hi,

 

This is NOT a solution. I am also facing this problem.

 

After searching the forum and reading several threads, this one seems to exactly report my problem. As the only potential solution I have seen so far, people have suggested creating wrapper DLLs which is definitely not a practical solution for somebody who does not have the required software installed. The other point is that I have already dealt with several similar problems of passing nasty data to and from "call library function node" successfully just by using LV, but this MATLAB data type: mxArray is another thing!!

 

Problem Description:

 

I have a .mexw32 file that is generated by MATLAB from c code. I have changed the extension to .dll which is still allowed in this version of MATLAB. The DLL file contains one function named as "mexFunction" just like every MEX dll. Its prototype is expressed in MATLAB help as follows:

 

 void mexFunction(

    int nlhs, mxArray *plhs[],

    int nrhs, const mxArray *prhs[])

{

   /* more C code ... */

}

 

 

Therefore, there are four parameters. two of them are integers, but the other two are arrays of pointers to mxArray structures. There is a nice introduction to mxArray data type in here. It says: "an mxArray is MATLAB's structure for holding data and each element in plhs/prhs holds an mxArray of data."

 

Just to better understand mxArray, If you also look in MATLAB help under "MATLAB Data", it introduces a function called explore.c which converts the input data into mxArray and shows it on the screen. Here is an example:

 

>> explore(1001)

 

------------------------------------------------

Name: prhs[0]

Dimensions: 1x1

Class Name: double

------------------------------------------------

(1,1) = 1001 

 

 

Using the above information, I have created the following diagram for passing 11 doubles to a MEX dll and get back 52 doubles. Of course, it doesn't work yet! But, maybe I am missing a small point. Does anyone have a suggestion? 

 

 

 mxArray.PNG

 

 

Using LV 2009, MATLAB 2009b, Windows XP 32bit

 

Soroush 

0 Kudos
Message 5 of 6
(3,735 Views)

I have searched a bit more and the only solution seems to be using a wrapper DLL developed in C. 

 

mxArray is an abstract data type in C which means its structure is not publicly accessible! in the above example, I have used just the value (double) and tried to make a structure similar to mxArray, but it is incomplete because it is not possible to find about the exact details of mxArray. (see this)

 

Sometimes, firm negative answers are good enough!

 

 

0 Kudos
Message 6 of 6
(3,731 Views)