Given the prevalence of Matlab in the scientific community, it is rather common for Flywheel users to want to develop a Flywheel Gear that can execute Matlab code. As Matlab users will be aware, licensing considerations are seemingly unavoidable. However, many users don't realize that you can easily (well, relatively) compile your Matlab code and share it with the community, who can then execute the code using the freely available Matlab Compiler Runtime. It's this method that we take advantage of to build and generate Matlab Gears. As a developer, you can compile your Matlab code and include the resulting binary within a Gear that is built from a base MCR image (more on that later).
General Gear building principles are still to be followed with Matlab gears, however there are a few things to keep in mind, requirements, etc., some of which are specific to Matlab Gears, and outlined below.
General Matlab Gear Requirements
Of your Matlab code
- Must have no GUI interaction. Given that FW Gears run in a "headless" environment, code that requires a GUI, or any kind of user interaction mid processing stream, are not supported.
- Must run on linux: As the FW Gear execution environment is container based, we require that your execution environment similarly be linux-based.
Of your development and execution environment
- Linux - you must be able to run and compile the code on Linux - currently, it is not possible to cross-compile for platforms. That means that Matlab code cannot be compiled on OSX, or WIN.
- Docker - Install instructions for Ubuntu are here. You will need Docker to build and test your Gear.
Of your Docker image
- You need to have (or build) docker images that contain the MCR (Matlab Compiler Runtime). Flywheel has some images that can be used as a base image for your project. MCR images can be browsed here. To reduce your development effort, it’s recommended to have a look at those images and use one that is already available.
- Important notes on the Matlab MCR
- The version of Matlab which you use to compile the code determines the version of the MCR that should be used to execute. They must match, or it will not run.
Available MCR images via Flywheel Dockerhub
Each of the Matlab MCRs that have been pre-built and are available to be pulled from Dockerhub are listed in the table below.
|Matlab MCR Version|
Example Matlab Gears
Often times the best path forward is to look back (wait, what) at examples. Below are a few examples of compiled Matlab code being executed within Flywheel Gears:
- FLoc : A Flywheel Gear that can analyze data generated with the Functional localizer experiment used to define category-selective cortical regions (published in Stigliani et al., 2015).
- Gannet: Build context for a Gear that can run Gannet. Gannet is a software package designed for the analysis of edited magnetic resonance spectroscopy (MRS) data.
- DWI Split Shells: Extract individual diffusion shells from multi-shell DWI data. Output includes a NIfTI, BVEC, and BVAL file for each diffusion shell found in the data.
- DTI Error: Calculate RMSE between the measured signal and the ADC (or dSIG) based on tensor model fit provided by dtiInit.
- Apply Canonical X-Form: Reorient NIfTI data and metadata fields into RAS space by estimating and applying a canonical transform.
Contributed by Noah Mercer
- Edit <SPM_HOME>/config/spm_make_standalone.m and comment out the line in the 'Compiliation' section that begins with 'mcc'. This will skip the final compilation step that actually builds spm into its own SAE, which isn't necessary.
- Run spm_make_standalone at the Matlab prompt. This will configure SPM to allow it to run as part of your SAE.
Error using strfind