Developer Zone

Advanced Software Development with MATLAB

What About the Apps, I Hear You Ask?

Hi all, if you are not yet aware, the R2017a release of MATLAB is now available, and it's packed full of features! If you have a chance be sure to check some of them out. Readers of this blog may be particularly interested in the Advanced Software Development section. We'll definitely be exploring more of what's new in the release soon on the blog, so stay tuned.

Today, though, I am excited to have Amy here again with more goodness on creating and sharing your MATLAB toolboxes, This time, she is focusing on integrating MATLAB Apps into the toolbox. Here's Amy.

In a previous post, I described how to set up your development environment when developing and packaging a MATLAB toolbox. As a result of that discussion, Curtis asked about packaging MATLAB Apps in toolboxes using this workflow, and I'll be talking about some of the best practices in this post.

MATLAB Apps are interactive graphical applications written to perform technical computing tasks and can be launched from the Apps tab of the MATLAB Toolstrip. They were introduced in R2012b before custom toolboxes. With the introduction of custom toolboxes, it's natural to want to include apps within toolboxes as apps can provide an easy access point to code contained within your toolbox.

The toolbox packaging tool recognizes any .mlappinstall files within the specified toolbox folder and includes the apps in the .mltbx file automatically as shown in the screenshot below.

Why package an app within a toolbox?

Toolbox code is available for use by end users either at the MATLAB command line or in user scripts once the toolbox is installed. By contrast, an app can be launched just by clicking on the icon in the Apps tab of the MATLAB Toolstrip. MATLAB will automaticaly install apps packaged with your toolbox and adds them to the Apps Gallery. You might want to have:

  • an app that demonstrates how to use functions in your toolbox;
  • more than one app which shares the same toolbox code;
  • apps that launch other apps in the same toolbox;
  • commands that can launch apps from the command line or in user scripts after the toolbox is installed.

Where do you package the app code?

Like the toolbox packaging tool, the app packaging tool performs code dependency analysis to identify files required to run an app and includes these files in the package automatically. If an app is packaged within a toolbox, it is important that these files are not duplicated or packaged more than once in the .mltbx file. A MATLAB App requires a main or app launcher file, which typically is a simple function that launches the UI. To avoid duplication, I suggest only packaging the app launcher file in the .mlappinstall file, and all other code and dependencies are packaged in the .mltbx file. In other words, when packaging the app, remove all app files apart from the app launcher file from the MATLAB path so that these files aren't identified in the dependency analysis.

App launcher file

Here is a simple app launcher file:

function varargout = myAppLauncher()
%myAppLauncher  wrapper to launch 'myApp'
%
%   f = myAppLauncher() launches 'myApp' and returns
%   the handle to the figure window.

% Create application
fh = myApp();

% Return figure handle
if nargout == 1
   varargout{1} = fh;
end

end % myAppLauncher

Try it!

Give it a try and let us know what you think by leaving a comment below!




Published with MATLAB® R2017a

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.