Main Content

Create Standalone Application Using Standalone Application Compiler App

This example shows how to use the Standalone Application Compiler app to package a MATLAB® function into a deployable standalone application that does not require MATLAB to run.

Before R2025a: Create a standalone application using the previous version of the Standalone Application Compiler app as shown in Create Standalone Application from MATLAB Function Using Application Compiler App (R2024b).

Create MATLAB Function

First, write MATLAB code to compile into a standalone application. You can compile a MATLAB function, class, or app of one of these file types: .m, .p, .mlx, .mlapp, or .mex. Your code must be in a finished state and ready for the end user to run. For more information, see Write Deployable MATLAB Code.

For this example, create a function file named modfun.m that contains this code.

function modfun(m,n)
axis([-1 1 -1 1])
axis square
axis off
hold on
z = exp(2i*pi*(0:n)/n);
for j = 0:n
    zj = [z(j+1),z(mod(j*m,n)+1)];
    plot(real(zj),imag(zj))
end
end

The modfun function connects n equally spaced points around the complex unit circle with straight lines using multiples of m as the modulus. The jth line connects z(j+1) to z(mod(j*m,n)+1).

Create Project and Compiler Task

Create a compiler task for your function by using the Standalone Application Compiler app. Compiler tasks allow you to compile files in a project for a specific deployment target.

To open the app, on the Apps tab, expand the Apps gallery. In the Application Deployment section, click Standalone Application Compiler.

Application Deployment section of the Apps gallery

You can also open the app using the standaloneApplicationCompiler function at the MATLAB Command Window.

After you open the app, the Create Compiler Task dialog box prompts you to add a compiler task to a new or an existing MATLAB project. For this example, select Start a new project and create a compiler task and create a new project named ModfunProject in your working folder. For more information on creating and using MATLAB projects, see Create Projects.

Create compiler task dialog box with the text 'To deploy your MATLAB code, you need a MATLAB project to organize code and a compiler task to handle deployment.' The option 'Start a new project and create a compiler task' is selected.

A new compiler task named StandaloneDesktopApp1 opens in the Editor. You can compile code for other deployment targets by opening the Compiler Task Manager app or going to the Manage Tasks tab and creating a new compiler task.

Project tab of the Standalone Application Compiler app shows the Project panel on the left and the Compiler Task Editor on the right

Specify Build Options

You can specify options for the standalone application and its installer before packaging to customize the building and packaging process. For instance, you can add a splash screen or icon, obfuscate the MATLAB code, and specify the method of including MATLAB Runtime in the generated installer.

For this example, in the Main File section of the compiler task, click Add Main File and select modfun.m. In the Project panel, the file now has the labels Design and Main Function.

Main file section of the compiler task with a button labeled 'Change Main File.' The file modfun.m has been added.

In the Application Info section, replace the string My Desktop Application with the name for your standalone application, Modfun Application. You can specify other details in this section, such as the author, company, and description.

Application info section of the compiler task

In the Executable Details section, name the executable Modfun. Under Application Type, select Standalone Windows Application if you are using Windows®; otherwise, select Standalone Application. Under Input Type, select Treat inputs to the app as a numeric MATLAB double.

Executable details section of the compiler task

In the Installer Details section, name the generated installer ModfunInstaller. You can also specify other installer options such as the runtime delivery method. These options correspond to the options available with the compiler.package.installer function.

Installer details section of the compiler task

View Code and Package Standalone Application

To view code that contains instructions on building and packaging your component, click the arrow next to the Export Build Script button and select Show Code. On the right, a window opens that displays a deployment script with the compiler.build.standaloneApplication or compiler.build.standaloneWindowsApplication and compiler.package.installer (MATLAB Compiler SDK) functions that correspond to your build options.

You can convert this code to a MATLAB script file by clicking the Export Build Script button. Running the generated build script is equivalent to clicking the Build and Package button.

Two buttons labeled Export Build Script and Build and Package

To generate both the standalone application and an installer, click Build and Package. To create the application executable without an installer, click Build and Package > Build.

The compiler generates files in the <compiler_task_name>/output folder in your project folder. The build subfolder contains the standalone application executable, and the package subfolder contains an installer for your standalone application along with MATLAB Runtime. To choose a different output location for the generated files, update the paths in the Output Locations section.

Test and Deploy Application

You can test the application in MATLAB before deployment. Run the executable in the MATLAB Command Window using the bang operator and the inputs 111 and 200 to view the figure.

!D:\Work\ModfunProject\StandaloneDesktopApp1\output\build\Modfun.exe 111 200

MATLAB figure window showing the unit circle drawn by the modfun function

To deploy your application outside of MATLAB, you must have MATLAB Runtime installed at the same version as the MATLAB version used to build the application. Ensure that your end users can run the application by including MATLAB Runtime in the installer or by supplying users with information on how to download it. For information on installing and using MATLAB Runtime, see About MATLAB Runtime.

For details on installing your standalone application, see Install Deployed Application. For more information on deployment, see Steps for Deployment with MATLAB Compiler.

See Also

| |

Topics