Tuesday, April 5, 2016

What toolboxes are required by this Matlab code base?

Matlab is distributed as a core application plus a large menu of available toolboxes and blocksets which can be licensed separately. Today I was helping a Matlab user install an additional toolbox required by a project he's taking on. He mentioned that this is starting from existing Matlab code he received from another user.

When you 'inherit' existing code from someone else, one key question from the start is what are the dependencies. Of course good computer engineering practice includes documenting one's code and identifying all dependencies, to spare future users the need to trace them all manually later. But we can't always count on the person before us having done so.

So you could open a Matlab project and find it requires any number of different toolboxes. Does  your copy of Matlab have all the ones it needs? To find out, you could start the code and wait for it to halt with error messages about missing toolboxes, then see if you have a license for that, and get it installed. (You just have to hope you trial run(s) exercise every branch that reaches a dependency you need to resolve! Want to solve the halting problem while we're here?)

Fortunately, in Matlab (since R2012a) there is a 'dependencies' function, including a call to generate a list of the Matlab toolbox names that the specified body of .M code requires. You pass it a path to the location of the code you want checked, and it returns a list of required toolboxes. Voila!

Here is the Mathworks page on this:

http://www.mathworks.com/help/simulink/slref/dependencies.toolboxdependencyanalysis.html

To automate testing if all the listed toolboxes are installed, you can call

ver toolboxname

You can also test if a license is available for a toolbox using Matlab's license() function:

http://www.mathworks.com/help/matlab/ref/license.html

The license('inuse') command lists what licenses your current Matlab session has checked out (this could include any licenses you accessed during the same session that the license server has not yet timed out, including ones used by a previous task.)