Create a standalone application for deployment outside MATLAB
compiler.build.standaloneApplication(
creates a deployable standalone application using a MATLAB® function, class, or app specified by AppFile
)AppFile
. The
executable file extension is determined by your operating system.
compiler.build.standaloneApplication(
creates a standalone application with additional options specified as one or more name-value
pairs. Options include the executable name, help text, and icon image.AppFile
,Name,Value
)
compiler.build.standaloneApplication(
creates a standalone application with additional options specified by a
opts
)compiler.build.StandaloneApplicationOptions
object
opts
. You cannot specify any other options using name-value
pairs.
Create a standalone application that displays a magic square.
Write a MATLAB function that generates a magic square. Save the function in a file named
mymagic.m
.
function out = mymagic(in) if ischar(in) in=str2double(in); end out = magic(in)
Build a standalone application using the
compiler.build.standaloneApplication
command.
compiler.build.standaloneApplication('mymagic.m');
This generates the following files within a folder named
mymagicstandaloneApplication
in your current working directory:
mymagic.exe
or mymagic.sh
—Executable file
that has the .exe
extension if compiled on a Windows® system or the .sh
extension if compiled on
Linux® or macOS.
mccExcludedFiles.log
—Log file that contains a list of any
toolbox functions that were not included in the application. For information on
non-supported functions, see MATLAB Compiler Limitations.
readme.txt
—Readme file that contains information on
deployment prerequisites and the list of files to package for deployment.
requiredMCRProducts.txt
—Text file that contains product IDs
of products required by MATLAB Runtime to run the application.
To run mymagic
with the input argument 4
,
execute !mymagic 4
in the MATLAB command window from the mymagicstandaloneApplication
folder, mymagic.exe 4
in an MS-DOS window, or ./mymagic.sh
4
in a Linux or macOS terminal window.
The application outputs a 4
-by-4
magic
square.
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
Customize a standalone application using name-value pairs on a Windows system to specify the executable name and version, add a function file, and interpret command line inputs as numeric doubles.
Write a MATLAB function that uses a subfunction to compute the diagonal components of a
magic square. Save the functions to files named mymagicdiag.m
and
mydiag.m
.
function out = mymagicdiag(in)
X = magic(in);
out = mydiag(X)
function out = mydiag(in)
out = [diag(in)]';
Build the standalone application using name-value pair arguments to specify additional options.
compiler.build.standaloneApplication('mymagicdiag.m',... 'ExecutableName','MagicDiagApp','ExecutableVersion','1.1',... 'AdditionalFiles','mydiag.m',... 'TreatInputsAsNumeric','On')
The following files are generated within a folder named
MagicDiagAppstandaloneApplication
in your current working
directory:
MagicDiagApp.exe
mccExcludedFiles.log
readme.txt
requiredMCRProducts.txt
To run MagicDiagApp.exe
with the input argument
4
, execute !MagicDiagApp.exe 4
in the
MATLAB command window from the
MagicDiagAppstandaloneApplication
folder or execute
MagicDiagApp.exe 4
in an MS-DOS window.
The application outputs the diagonal entries of a
4
-by-4
magic
square.
16 11 6 1
Customize multiple standalone applications using a compiler.build.StandaloneApplicationOptions
object on a Windows system to specify a common output directory, interpret command line inputs
as numeric doubles, and display progress information during the build process.
Write a MATLAB function that generates a magic square. Save the function in a file named
mymagic.m
.
% mymagic.m function out = mymagic(in) out = magic(in)
Create a StandaloneApplicationOptions
object using the function
mymagic.m
and additional options specified as name-value
pairs.
opts = compiler.build.StandaloneApplicationOptions('mymagic.m',... 'OutputDir','D:\Documents\MATLAB\work\MagicBatch',... 'TreatInputsAsNumeric','On',... 'Verbose','On')
opts = StandaloneApplicationOptions with properties: ExecutableName: 'mymagic' CustomHelpTextFile: 'D:\Documents\MATLAB\work\helpfile.txt' EmbedArchive: on ExecutableIcon: 'C:\Program Files\MATLAB\R2020b\toolbox\compiler\resources\default_icon_48.png' ExecutableSplashScreen: 'C:\Program Files\MATLAB\R2020b\toolbox\toolbox\compiler\resources\default_splash.png' ExecutableVersion: '1.0.0.0' AppFile: 'D:\Documents\MATLAB\work\mymagic.m' TreatInputsAsNumeric: off AdditionalFiles: {} AutoDetectDataFiles: on Verbose: on OutputDir: 'D:\Documents\MATLAB\work\MagicBatch'
Pass the StandaloneApplicationOptions
object as an input to the
build function.
compiler.build.standaloneApplication(opts);
Use dot notation to change the input file of an existing
StandaloneApplicationOptions
object.
opts.AppFile = 'mymagic2.m';
This allows you to compile multiple applications using the same options object.
Create a standalone application and save information about the build type,
included files, and build options to a compiler.build.Results
object.
Save the compiler.build.standaloneApplication
information to a
Results
object by declaring an output variable.
results = compiler.build.standaloneApplication('mymagic.m')
results = Results with properties: BuildType: 'standaloneApplication' Files: {2×1 cell} Options: [1×1 compiler.build.StandaloneApplicationOptions]
The Files
property contains the paths to the generated standalone
executable and readme files.
AppFile
— Path to main filePath to the main file used to build the application, specified as a row character vector or a string scalar. The file must be a MATLAB function, class, or app of one of the following types: .m, .p, .mlx, .mlapp, or a valid MEX file.
Example: 'mymagic.m'
Data Types: char
| string
opts
— Standalone application build optionscompiler.build.StandaloneApplicationOptions
objectStandalone application build options, specified as a compiler.build.StandaloneApplicationOptions
object.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'EmbedArchive','on'
'AdditionalFiles'
— Additional filesAdditional files to be included in the standalone application, specified as a character vector, a string scalar, a string array, or a cell array of character vectors. File paths can be relative to the current working directory or absolute.
Example: 'AdditionalFiles',["myvars.mat","myfunc.m"]
Data Types: char
| string
| cell
'AutoDetectDataFiles'
— Flag to automatically include data files'on'
(default) | on/off logical valueFlag to automatically include data files, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A
value of 'on'
is equivalent to true
, and
'off'
is equivalent to false
. Thus, you can
use the value of this property as a logical value. The value is stored as an on/off
logical value of type matlab.lang.OnOffSwitchState
.
If you set this property to 'on'
, then data files that
are provided as inputs to certain functions (load
,
fopen
, etc) are automatically included in the standalone
application.
If you set this property to 'off'
, then data files must
be added to the application using the AdditionalFiles
property.
Example: 'AutoDetectDataFiles','Off'
Data Types: logical
'CustomHelpTextFile'
— Path to help file''
(default) | character vector | string scalarPath to a help file containing help text for the end user of the application, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.
Example: 'CustomHelpTextFile','D:\Documents\MATLAB\work\helpfile.txt'
Data Types: char
| string
'EmbedArchive'
— Flag to embed deployable archive (.ctf
file) in application'on'
(default) | on/off logical valueFlag to embed the standalone archive, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A
value of 'on'
is equivalent to true
, and
'off'
is equivalent to false
. Thus, you can
use the value of this property as a logical value. The value is stored as an on/off
logical value of type matlab.lang.OnOffSwitchState
.
If you set this property to 'on'
, then the standalone
archive is embedded into the standalone executable.
If you set this property to 'off'
, then the standalone
archive is generated as a separate file.
Note
This property is ignored for Java libraries.
Example: 'EmbedArchive','Off'
Data Types: logical
'ExecutableIcon'
— Path to icon imagematlabroot
\toolbox\compiler\resources\default_icon_48.png
(default) | character vector | string scalarPath to an icon image, specified as a character vector or a string scalar. The
image is used as the icon for the standalone application executable. The path can be
relative to the current working directory or absolute. Accepted image types are
.jpg
, .jpeg
, .png
,
.bmp
, and .gif
.
Example: 'ExecutableIcon','D:\Documents\MATLAB\work\images\myIcon.png'
Data Types: char
| string
'ExecutableName'
— Name of generated application'AppFile'
(default) | character vector | string scalarName of the generated application, specified as a character vector or a string
scalar. The default value is the file name of AppFile
. Target
output names must begin with a letter or underscore character and contain only
alpha-numeric characters or underscores.
Example: 'ExecutableName','MagicSquare'
Data Types: char
| string
'ExecutableVersion'
— Executable version'1.0.0.0'
(default) | character vector | string scalarExecutable version, specified as a character vector or a string scalar.
Note
This is only used on Windows operating systems.
Example: 'ExecutableVersion','4.0'
Data Types: char
| string
'OutputDir'
— Path to output directory'ExecutableName
standaloneApplication'
(default) | character vector | string scalarPath to the output directory where the build files are saved, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.
If no path is specified, a build folder named
is created in the current working directory.
standaloneApplicationExecutableName
Example: 'OutputDir','D:\Documents\MATLAB\work\MagicSquarestandaloneApplication'
Data Types: char
| string
'TreatInputsAsNumeric'
— Flag to interpret command line inputs'off'
(default) | on/off logical valueFlag to interpret command line inputs as numeric values, specified as
'on'
or 'off'
, or as numeric or logical
1
(true
) or 0
(false
). A value of 'on'
is equivalent to
true
, and 'off'
is equivalent to
false
. Thus, you can use the value of this property as a logical
value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
If you set this property to 'on'
, then command line
inputs are treated as numeric MATLAB doubles.
If you set this property to 'off'
, then command line
inputs are treated as MATLAB character vectors.
Example: 'TreatInputsAsNumeric','On'
Data Types: logical
'Verbose'
— Flag to control build verbosity'off'
(default) | on/off logical valueFlag to control build verbosity, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A
value of 'on'
is equivalent to true
, and
'off'
is equivalent to false
. Thus, you can
use the value of this property as a logical value. The value is stored as an on/off
logical value of type matlab.lang.OnOffSwitchState
.
If you set this property to 'on'
, then the MATLAB command window displays progress information indicating code
generation stages and compiler output during the build process.
If you set this property to 'off'
, then the command
window does not display progress information.
Example: 'Verbose','On'
Data Types: logical
results
— Build resultscompiler.build.Results
objectBuild results, returned as a compiler.build.Results
object. The Results
object contains the build type, the paths to the compiled files, and the build options, specified as a StandaloneApplicationOptions
object.
applicationCompiler
| compiler.build.StandaloneApplicationOptions
| compiler.build.standaloneWindowsApplication
| compiler.package.installer
| mcc