Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Monday, June 30, 2008

Wrapping up MATLAB/LabView Problem

So here is some final thoughts on the problem of compiling MATLAB code into C shared libraries to use with LabView; before I forget about it all now that I decided to stop worrying about it:

- The first problem is that Matlab uses a custom data type called MxArray, and one needs to create a wrapper function that takes in standard data types (doubles, integers, etc.) and calls the appropriate Matlab compiled functions with the arguments passed as MxArrays.

- After creating the wrapper, you can re-compile it all to end up with a .dll and a .h file.

- These files can be used with the function library node sub-vi in LabView, and the appropriate functions should show up. However...

- The first function to call is one that loads the global MCR (Matlab Complie Runtime or something similar), which should only be stopped after one finishes using any Matlab libraries.

- Then one can call the set of initialization functions for each matlab function complied into the shared librarry. After initializing, one can call the excecuting function, and lastly the terminate function. The initalization/termination funciton basically create a new local MCR instance for each one.

- The last step is to call the global termination, to stop the global MCR.

- This all sounds fine, until you start implementing it. It is just a PITA to get it working.

Wednesday, June 4, 2008

Compiling Matlab code into Shared Libraries

It's been a long time since our last post. Many things have happened since, and even though we intended to use this blog as a progress report log, I am starting to realize that it will be more similar to a "Lessons Learned" kind of log, at least during the early stages.

Today I spent a few hours trying to get some .m files working in LabView by compiling them into .dll shared libraries, and importing them using the new Shared Library Import Wizard that came out on v8.2 of LabView. Read lots of forum threads, and spent some time staring at the command line prompt.

So far, I've managed to compile the code by using the following:

mcc -a neededmatfiles.mat -W lib:libraryName -T link:lib filestocomiple.m

This results in a .dll and some other necessary files.

It turns out, however, that the choice of compiler (which can be configured using "mbuild -setup" is an important one. The Lcc-win32 compiler that comes with Matlab doesn't seem to be doing the work, and I've read on some forums that the Visual Studio 7.0 compiler is our best bet. So now I'm looking for a computer with it, since the "free" student version (DreamSpark) is not so easy to get.

Update (06/06/08): I might have found the solution here:
http://forums.ni.com/attachments/ni/170/7347/1/dllmatlablabview.pdf