4

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.

chappjc
  • 30,359
  • 6
  • 75
  • 132
Samuel O'Malley
  • 3,471
  • 1
  • 23
  • 41

3 Answers3

4

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.

chappjc
  • 30,359
  • 6
  • 75
  • 132
  • 1
    Its not 100% clear from the link you gave, does Matlab Coder work nicely with Toolkits? – Samuel O'Malley Oct 29 '13 at 05:18
  • @omalsa04 - I just updated with two links listing supported functionality. [Most toolkit functions are supported](http://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--categorical-list.html). In addition to that categorical list, here is the [subset overiew link](http://www.mathworks.com/products/matlab-coder/description2.html) and the [function list link](http://www.mathworks.com/help/coder/language-supported-for-code-generation.html). – chappjc Oct 29 '13 at 05:20
  • Also GUIs are not supported by MATLAB Coder – am304 Oct 29 '13 at 08:36
  • 1
    @am304 - Correct, no Java, only C and C++ code generation. That precludes most graphical functionality. I think the aim is primarily speeding up and exporting algorithms. – chappjc Oct 29 '13 at 08:43
3

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.

MrAzzaman
  • 4,734
  • 12
  • 25
  • The standalones generated by MATLAB Compiler cannot be run in MATLAB. The separate MATLAB Coder product is needed to do this. It can create MEX files from .M code. See my answer. – chappjc Oct 29 '13 at 05:12
  • 2
    Yes, but only a subset of MATLAB functions are supported, and not every Toolbox is supported. Given that this question was about sending code to collaborators without the necessary toolboxes, that is a potential sticking point. If code was compiled to a shared library using the Compiler, it would be fairly simple to write C/C++ code which could be compiled into MEX functions. That said, if all of the OPs code is covered by the Coder toolbox, then yes, it would be a better option. – MrAzzaman Oct 29 '13 at 05:25
  • Thanks guys for your responses. I like how Matlab Coder works, however I don't think it has the Toolbox capabilities that Matlab Compiler has. Specifically Mapping and Parallel Toolboxes. – Samuel O'Malley Oct 29 '13 at 05:47
  • I just added an edit to my original post, I neglected to mention this before but some of the applications I'd need to package would have GUIs. – Samuel O'Malley Oct 29 '13 at 05:51
  • 1
    @omalsa04 - Those toolboxes are unlikely to be supported by Coder any time soon, especially Parallel Computing. So, Compiler might be your only choice. – chappjc Oct 29 '13 at 05:51
  • Matlab Compiler is still cheaper than requiring remote sites to have licenses for multiple Toolboxes. Thanks both of you! – Samuel O'Malley Oct 29 '13 at 05:54
1

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

Rob Purser
  • 11
  • 3