This week, guest blogger Jacob writes about how to use MATLAB-based tools to develop applications that are deployment-ready from inception.
Deployed applications rely on the MATLAB Compiler Runtime (the MCR) for execution. The MCR differs from MATLAB in subtle but important ways. You will find it much easier to deploy your MATLAB-based applications if you code with these differences in mind. You can learn how to develop deployable applications by reading our documentation and blog articles. To help you keep track of all the details, we're working on pushing some of this information into our development tools. One of first tools we enhanced for deployment is the MATLAB code analyzer, mlint.
Contents
Turning Deployment Messages On
The code analyzer examines MATLAB code to detect possible problems or improvements. The code analyzer is integrated into the MATLAB Editor so you can see its suggestions as you develop your code.
Code analyzer suggestions are divided into several categories (you can fine-tune which messages are shown through the Code Analyzer Preferences).
MATLAB Compiler (Deployment) Messages alert you when you use certain functions that may not deploy. However, you might not have noticed these messages before since this category is disabled by default. In order to enable this category of messages:
Catching Non-Deployable Code
With Deployment messages enabled, the code analyzer can help detect when you are developing problematic code. For example, Writing Deployable Code used the following as an example of code that may compile but yield undesired results at run-time:
cd mathFcns z = add(x,y); cd ../stringFcns s = add(s1,s2);
In the MATLAB editor, the code analyzer highlights both instances of the cd command. By hovering your cursor over the underlined word, you view the warning message:
MCC use of the CD function is problematic.
Furthermore, if you click on the message, you get an explanation and suggested action. In this case, the suggested action is to avoid use of the CD command.
Limitations of the Code Analyzer
The code analyzer can help catch many instances of non-deployable code. Most of these instances involve the use of known problematic functions like cd, addpath or help.
In fact, the Default Settings window in Code Analyzer Preferences displays all possible messages the code analyzer might display. Reading these messages helps you understand what code constructs the code analyzer is likely to catch.
While the code analyzer is a useful tool for detecting some instances of non-deployable code, it cannot detect all instances. For example, consider the following example which results in no warning or error message:
set(gca, 'ButtonDownFcn', 'LogButtonPress');
This code may result in a failure when deployed because MATLAB Compiler's dependency analysis (depfun) cannot detect that LogButtonPress is a function that must be included in the application. For this code to work in deployed mode, you must explicitly include LogButtonPress at compile-time (by using the -a switch in mcc). In this case, the code analyzer suffers from some of the same limitations that MATLAB Compiler's dependency analysis does---the inability to understand the contents of a string.
Use the Code Analyzer but Don't Depend on It
The code analyzer can help you to write deployable code, but it is not a substitute for understanding the compilation process or how running your application in MATLAB differs from running against the MCR. This understanding ultimately provides the best foundation for writing deployable code.
However, even if you cannot completely depend on the code analyzer to guarantee deployable code, you can still use it to quickly catch instances that might otherwise require lengthy debugging to correct. After all, problems caught while in development usually cost much less to fix than problems caught when the application is deployed.
Are there other MATLAB coding patterns for which you think the code analyzer should issue deployment warnings? Let us know here.
Get
the MATLAB code
Published with MATLAB® 7.11



Cool ! another post about my favorite toolbox!!
As you mentioned in this article , ML Compiler may not found functions which are specified as callbacks.
And it would be great if M-lint could add a message saying “use the %#function pragma to help MATLAB Compiler to locate functions called through feval, eval, or Handle Graphics® callback”
I often use this “trick” to be sure that my callbacks will be packaged with my standalone.
http://www.mathworks.com/help/toolbox/compiler/function.html
Now I think another enhancement will be about “Passing Arguments to and from a Standalone Application” . As we already talked in this blog, the input arguments we pass to our application from a system prompt are considered as string input. And therefore we have to use isdeployed and str2num. I have no idea how hard it would be to have this information displayed via a M-lint message.
For me , the 2 above items are the most often issues met by my colleagues which ignore or forget these considerations. M-Lint could help us to avoid this king of mistakes.
Another point may be to tell the programmer that if in his code he reads with imread a file (JPEG for example) which is not shipped with MATLAB, he will have to give manually this image with his standalone since ML Compiler will not package , encrypt this file.
Aurélien
http://blog.developpez.com/matlab4geek/
Aurelien-
It would be great if you could enter your ideas as enhancement requests. There’s a link on the right of the blog to do so. Thanks!
–Loren
No problem Loren. I will submit my ideas to Tech-Support team with a great pleasure!
# Invoke M-Lint Preferences by selecting File > Preferences > M-Lint # In the Default Settings box, locate the MATLAB Compiler (Deployment) Messages category and click Enable Category.
I guess it should be Preferences > Code Analyzer, not Preferences > M-Lint. (R2010b)
Aurélien,
Those are interesting suggestions. If you enter them as Loren suggests, we’ll take a look at implementing them. Thanks.
Jan,
You’re right. Thanks.
@Loren, Peter
I alreday submitted my enhancement requests . French Technical Support has created 2 gecks 713190 and 713187 .
Aurélien
Aurélien,
Thanks for doing that!
–loren