Clear Filters
Clear Filters

How to build a standalone application programmatically in R2019a?

13 views (last 30 days)
In the current MATLAB Compiler documentation there is a section on how to "Create Standalone Application Using Application Compiler App" that includes instructions on how to do this programmatically (e.g., "Create Standalone Application Using Application Compiler App"). Similar instructions do not exist in the R2019a documentation and I can't find any documentation on an alternative. Is it possible to build a standalone application programmatically in R2019a, or am I relegated to using the GUI only?
J. Alex Lee
J. Alex Lee on 11 Aug 2021
i just clicked on your 2019a doc link and saw that page 1-6 has the section titled "Create Standalone Application Using Application Compiler App"
Monika Jaskolka
Monika Jaskolka on 11 Aug 2021
There is the section "Create Standalone Application Using Application Compiler App", but it lacks any instructions on how to do it programmatically. It only contains GUI-based instructions.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 11 Aug 2021
I never use the GUI app, deploytool, to compile me apps. I always have a script where I call mcc programmatically because I want to do things, like ask the user (myself) if they've updated the version number, perhaps ask which m-files to compile (if there is a whole suite of them), time how long the compilation takes, and things like that. I have a script called compile.m and in there I call mcc to do the compilation programmatically, along with other things.
Jason Brasseur
Jason Brasseur on 20 Apr 2023
Hello Image Analyst - I'm curious if you'd be willing to share your compile.m script referenced above - compiling exe's programatically is of interest to me and being able to see another person's routine would be a helpful starting point.
Thank you and best regards!
Image Analyst
Image Analyst on 20 Apr 2023
Edited: Image Analyst on 20 Apr 2023
@Jason Brasseur here is an example of one. Sort of a general purpose one for me. I change the suite name and individual m-file names depending on the project it's being used with.
echo off;
format compact;
% Change this next line, and then the next line. The rest might not need much change.
suiteFolderName = 'Jason Project';
% List all the files to compile. Make sure they all end with .m.
mFilesToCompile = {'myapp.m', 'trainSegNet.m', 'predictMask.m', 'RenameImages.m'};
% Define the top level folders for the source code and the output executables.
workFolder = 'C:\Users\Jason\OneDrive\Matlab\work\';
outputTopFolder = 'C:\Users\Jason\OneDrive\Matlab\Compiled\';
% Create a file that says what MATLAB release we need to run the compiled application(s).
% Disable startup.m from being included in compiled programs. Does this by renaming 'startup.m' to 'startup (Disabled).m'.
% I'm doing this to avoid the warning about having cd in the startup.m file when it compiles.
% Change directory to the source code folder.
sourceCodeFolder = fullfile(workFolder, suiteFolderName);
if ~isfolder(sourceCodeFolder)
message = sprintf('Folder %s does not exist!', sourceCodeFolder);
return; % Can't find source code so we can't do anything.
promptMessage = sprintf('Have you updated the Version Number file already?');
button = questdlg(promptMessage, 'Yes - Continue', 'Yes - Continue', 'No - Cancel', 'Yes - Continue');
if strcmp(button, 'No - Cancel')
edit 'Version Number.txt';
% Specify the output folder, creating it if needed, where the executable will be placed after it's created.
outputFolder = fullfile(outputTopFolder, suiteFolderName);
if ~isfolder(outputFolder)
rehash toolboxcache;
fprintf('Toolbox cache has been successfully rehashed.\n');
% Loop over all filenames
numMFiles = length(mFilesToCompile);
for k = 1 : numMFiles
mFileName = mFilesToCompile{k};
if ~isfile(mFileName)
promptMessage = sprintf('%s m-file not found.\nDo you want to Continue compiling the other files,\nor Quit?', mFileName);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
fprintf('Skipping compile of %s m-file because it was not found.\n', mFileName);
fprintf('Beginning compile of %s application (#%d of %d) at %s ...\n', mFileName, k, numMFiles, datestr(now, 'HH:MM:SS AM'));
mcc('-m', mFileName, '-d', outputFolder);
% echo off;
% disp([repmat(char(8), 1, 11)]); % Get rid of "echo off" from command window.
fprintf('Finished compile of %s application at %s.\n', suiteFolderName, datestr(now, 'HH:MM:SS AM'));
elapsedSeconds = toc;
minutes = int32(floor(elapsedSeconds / 60));
seconds = elapsedSeconds - 60 * double(minutes);
message = sprintf('\nIt is done compiling %d m-files in %s.\nIt took %d minutes and %.1f seconds.\n', numMFiles, suiteFolderName, minutes, seconds);
% Reenable startup.m. Does this by renaming 'startup (Disabled).m' to 'startup.m'.
fprintf('%s\n', message);
PlaySoundFile('D:\WaveFiles\Effects', 'DingLing.wav');

Sign in to comment.

More Answers (0)


Find more on Standalone Applications 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!