This example shows how to generate a standalone application from MATLAB®. You package a pre-written function that prints a magic square to a computer's command console. The MATLAB Compiler™ produces an installer that installs the standalone application and all of the required dependencies on a target system. The target system does not require a licensed copy of MATLAB.
In MATLAB, examine the MATLAB code that you want deployed as a standalone application.
Open magicsquare.m
magicsquare.m
.
function magicsquare(n) if ischar(n) n = str2num(n); end disp(magic(n))
At the MATLAB command prompt, enter magicsquare(5)
.
The output appears as follows:
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
Open the Application Compiler.
On the toolstrip select the Apps tab.
Click the arrow at the far right of the tab to open the apps gallery.
Click Application Compiler to open the MATLAB Compiler project window.
Specify the main file of the MATLAB application you want to deploy.
In the Main File section of the toolstrip, click the plus button.
Note: If the Main File section of the toolstrip is collapsed, you can expand it by clicking the down arrow. |
In the file explorer that opens, locate and select the magicsquare.m
file.
magicsquare.m
is located in
.matlabroot
\extern\examples\compiler
Click Open to select the file and close the file explorer.
magicsquare.m is added to the list of main files and the plus button will be replaced by a minus button.
In the Packaging Options section of the toolstrip, verify that the Runtime downloaded from web check box is selected.
Note: If the Packaging Options section of the toolstrip is collapsed, you can expand it by clicking the down arrow. |
This option creates an application installer that automatically downloads the MATLAB Runtime and installs it along with the deployed MATLAB application.
Explore the main body of the MATLAB Compiler project window.
The project window is divided into the following areas:
Application Information — Editable information about the deployed application. This information is used by the generated installer to populate the installed application's metadata. See Customize the Installer.
Additional Installer Options — The default installation path for the generated installer. See Customize the Installer.
Files required for your application — Additional files required by the generated application. These files will be included in the generated application installer. See Manage Required Files in Compiler Project.
Files installed with your application — Files that are installed with your application. These files include:
Generated readme.txt
Generated executable for the target platform
Additional Runtime Settings — Platform specific options for controlling the generated executable. See Customize Application Runtime Settings.
Click Package.
The Package window opens while the application is being generated.
Select the Open output folder when process completes check box.
When the deployment process is complete a file explorer opens and displays the generated output.
It should contain:
for_redistribution
folder contains
the file that installs the application and the MATLAB Runtime.
for_testing
folder contains all
the artifacts created by mcc
like binaries and
jar, header, and source files for a specific target. Use these files
to test the installation.
for_redistribution_files_only
folder
contains the files required for redistribute of the application. Distribute
these files to users that have MATLAB or MATLAB Runtime installed
on their machines.
PackagingLog.txt
is a log file
generated by the compiler.
Click Close on the Package window.
This example shows how to install the standalone application you created in Create Standalone Application from MATLAB code.
Locate the MyAppInstaller_web
executable
in the for_redistribution
folder created by
the MATLAB Compiler.
Note: The file extension varies depending on the platform on which the installer was generated. |
Double click the installer to run it.
Note: Any information entered in the MATLAB Compiler project window's Application Information appears on this window. |
If you connect to the internet using a proxy server, enter the server's settings.
Click Connection Settings.
Enter the proxy server settings in the provided window.
Click OK.
Click Next to advance to the Installation Options page.
Note: On Linux® and Mac OS X you will not have the option of adding a desktop shortcut. |
Click Next to advance to the Required Software page.
If asked about creating the destination folder, click Yes.
Note: If the correct version of the MATLAB Runtime exists on the system, this page displays a message that indicates you do need to install a new version. If you receive this message, skip to step 10. |
Click Next to advance to the License Agreement page.
If asked about creating the destination folder, click Yes.
Read the license agreement.
Check Yes to accept the license.
Click Next to advance to the Confirmation page.
Click Install.
The installer installs the MATLAB generated application. If needed, it also downloads and installs the MATLAB Runtime.
Click Finish.
Run your standalone application.
Open a terminal window.
Navigate to the folder into which you installed the application.
If you accepted the default settings, you can find the folder in one of the following locations:
Windows® | C:\Program Files\magicsquare |
Mac OS X | /Applications/magicsquare |
Linux | /usr/magicsquare |
Run the application using the one of the following commands:
Windows | application\magicsquare 5 |
Mac OS X | ./magicsquare.app/Contents/MacOS/magicsquare 5 |
Linux | ./magicsquare 5 |
A 5-by-5 magic square is displayed in the console:
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9