Using isdeployed to avoid un-supported features with Application Compiler
이전 댓글 표시
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
Walter Roberson
2025년 4월 2일
Note that the long-term solution to this is to use Simulink Compiler, which does support compiling mixes of MATLAB and Simulink.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!