Using isdeployed to avoid un-supported features with Application Compiler
Show older comments
I'm using the Application Compiler to compile my code into a standalone executable. I have some features in my code that cannot be compiled due to the use of un-supported functions/classes/types (e.g. Simulink objects). I'm trying to get around this by wrapping the parts of the code that use un-supported functions in if isdeployed blocks. The un-supported features use hundreds of .m files, but can be disabled by a single if isdeployed block at the top level.
When I open Application Compiler and add my main function, it auto-detects all of the "Files required for your application to run". This auto-detection does not respect or understand the if isdeployed block. The application compiles & runs, but the problem is that there are many extra & unnecessary files included in the compilation process.
How can I tell the Application Compiler to NOT include any files that won't actually be used in the compiled code? These are 2 ways I've come up with, and neither is great.
- Manually remove each un-needed .m file. Lots of manual work.
- Comment out the feature (instead of using an if isdeployed block). Not ideal because I can't have the same code in my git repo that does both in-matlab with the extra feature and compiled without the feature.
Here's an example. This is the main file that is compiled:
function [out] = compileMe(in)
% Test function
out = sprintf("I got %s", in);
if isdeployed
tmp = helperFun();
end
end
And here is the helperFun, which should not be included in the compilation:
function [tmp] = helperFun()
% Not supported in Matlab Compiler
tmp = Simulink.Block;
end
This is what I get by running the Application Compiler:

While there is just 1 "helperFun" in this example, in my real code there are hundreds of .m files here that would be annoying to remove manually.
1 Comment
Walter Roberson
on 2 Apr 2025
Note that the long-term solution to this is to use Simulink Compiler, which does support compiling mixes of MATLAB and Simulink.
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!