Skip to content

MATLAB mex bindings

Jeff Daily edited this page Aug 1, 2017 · 4 revisions

Although MATLAB can call native Python code, we have made MATLAB bindings to FNCS available via MATLAB's mex capabilities. See this Mathworks website for more details.

All of the mex files are located in the Matlab subfolder of the FNCS source distribution. The process of building the mex interfaces will depend on whether you're running on Windows, OSX, or Linux.

Windows instructions

Since FNCS v2.1.2, we provide a precompiled FNCS library with its dependencies from our https://github.com/FNCS/fncs/releases page. Expert users can still build their own library following the instructions for building on windows. Since most MATLAB installations are 64-bit, we recommend using the 64-bit FNCS library.

At this point, we assume you have a folder containing the libfncs.dll and its dependencies. We must put the MEX files into this same directory, including the build_mex.bat batch file. These files are located in the main FNCS distribution under the "matlab" folder. Copy every file from FNCS\matlab to the folder containing the FNCS library. Lastly, copy the FNCS C++ header file FNCS\fncs\src\fncs.hpp to this folder, as well. If you've followed these directions, you should have something that looks like:

You'll notice a helper batch file called "build_mex.bat". Double-click. It assumes the "mex" utility that came with your MATLAB installation is in your %PATH% (and it should be). It simply loops through all of the *.cpp files in the directory and calls "mex" for each one, passing appropriate linker and preprocessor flags to the mex utility. This assumes you have an appropriate C++ compiler installed, for example Visual Studio 2010 if you followed the building on windows instructions, or perhaps the Microsoft Windows SDK for Windows 7 if someone else built the FNCS library and dependencies for you.

Assuming all goes well, you'll get a bunch of files that look perhaps like *.mexw64. This indicates you've installed a 64-bit version of MATLAB. This is the most common practice on modern, 64-bit workstations. That's why we had you copy the "x64" build of the FNCS libraries so that it matched the 64-bit platform.

In order to use FNCS from MATLAB, you'll need to set the MATLAB search path. Something like the following, with your username replacing the <user> in the path below.

>> path(path, 'C:\Users\<user>\Documents\FNCS_MEX')

By default, MATLAB uses C:\Users<user>\Documents\MATLAB as part of its path. You could place your fncs.zpl configuration file there and/or all of the compiled MEX files there and then not have to worry about setting your path each time. Then you can call fncs functions as if they were built-in MATLAB functions. For example,

>> fncs_initialize()

OSX instructions

TODO.

Linux instructions

Instructions are similar to the Windows instructions, but you will be running "build.sh" instead to build the mex files. You must first set the FNCS_PREFIX environment variable to point to the same --prefix used when configuring your FNCS installation. You will end compiling many *.mexa64 objects.

Home

Clone this wiki locally