Samuel O'Malley
Samuel O'Malley

Reputation: 3551

How can I package a MATLAB application that utilises toolboxes?

I want to package up an application in MATLAB for another team to use. They will have an appropriate version of MATLAB to run this application, but they might not necessarily have licenses for all the toolboxes used by the application.

Is there a way to "bundle" the toolboxes into the application so that they do not require expensive licenses to run it?

If not, is it possible to create a stand-alone/license independent MATLAB application a different way?

EDIT: Some of these applications might feature GUIs as well as command line interfaces.

Upvotes: 4

Views: 631

Answers (3)

Rob Purser
Rob Purser

Reputation: 11

Disclosure: I work for MathWorks and contributed to the resource below:

You may find this guide from MathWorks helpful: "Best Practices for MATLAB Toolbox Development" on GitHub. This is under a permissive license so that people can redistribute it freely and incorporate it in their own organization’s best practices.

Here are some of the key recommendations you'll find in the guide:

  • Everything that is intended to be delivered to end users goes in a folder called “toolbox”.
  • Everything to help authoring teams collaborate, such as README.md and build utilities go in the root of your source repository.
  • Document via examples in an “examples” folder in your toolbox folder
  • Package and release your toolbox to share it with others so that you know what version your users have. Use semantic versioning.
  • Consider using argument validation, namespaces, MATLAB apps, and live tasks to enhance code quality and productivity.
  • Make your toolbox more robust through unit testing, MATLAB Projects, and the new buildtool.

We also have included a complete example that implements all the best practices.

https://github.com/mathworks/toolboxdesign

Upvotes: 1

chappjc
chappjc

Reputation: 30579

To generate code that can be run by MATLAB, you need the MATLAB Coder. The codegen command will generate the executables that can be run in MATLAB. Loren of MathWorks has a nice blog post on the product.

Here is an example of how to use codegen to create a MEX function from MATLAB code.

One big caveat is that with MATLAB Coder, the complete functionality of MATLAB is not yet available for compilation. This is because the generated binaries do not require the MATLAB Compiler Runtime (MCR), which is essentially a headless MATLAB virtual machine. Instead MATLAB Coder generates C code that is truly standalone, but the code generation is somewhat limited as a result. Here is a description of the subset of functionality, and here are complete lists of functions supported. Most toolkit functions appear to be supported according to the categorical list.

If the required functions are not supported, then it will be necessary to use the Compiler to generate standalone libraries and roll your own MEX interface to those libraries, as MrAzzaman indicated. Another possibilities is to use the loadlibrary function to directly load the Compiler-generate libraries, although I have never tried this last option. If you can't successfully interface with these libraries back in MATLAB, the MATLAB compiler can of course be used to generate a standalone executable. The deploytool simplifies the process of packaging the code and its dependencies.

Upvotes: 4

MrAzzaman
MrAzzaman

Reputation: 4768

The MATLAB Compiler sounds like exactly what you need. Unfortunately, it is a separate Toolbox which you would have to purchase.

EDIT: I should note that this will compile your MATLAB code into an application/library, not MATLAB code. The other team would still be able to use it with MATLAB, I believe, but I don't think they would be able to see the code itself.

Upvotes: 3

Related Questions