This example shows how to generate a MATLAB® function from a symbolic expression and use the function to create a standalone application with MATLAB Compiler™.
This example follows the steps described in Create Standalone Application from MATLAB (MATLAB Compiler) and updates the steps to generate a MATLAB function from a symbolic expression.
First, create the second-order differential equation
as a symbolic equation using
syms y(t); ode = diff(y,2) + diff(y)/2 + 2*y == 0;
To solve the differential equation, convert it to first-order differential equations by using the
V = odeToVectorField(ode);
Next, convert the symbolic expression
V to a MATLAB function file by using
matlabFunction. The converted function in the file
myODE.m can be used without Symbolic Math Toolbox™. The converted function is deployable with MATLAB Compiler.
Write a MATLAB script named
plotODESols.m that solves the differential equation using
ode45 and plots the solution. Save it in the same directory as
sol = ode45(@myODE,[0 20],[0 4]); x = linspace(0,20,200); y = deval(sol,x,1); plot(x,y) xlabel('Time t') ylabel('Displacement y')
You can use this script to create and deploy standalone application using Application Compiler app.
On the MATLAB Apps tab, in the Apps section, click the arrow to open the apps gallery. Under Application Deployment, click Application Compiler. The MATLAB Compiler project window opens.
Alternately, you can open the Application Compiler app by entering
applicationCompiler at the MATLAB prompt.
In the MATLAB Compiler project window, specify the main file of the MATLAB application that you want to deploy.
In the Main File section of the toolstrip, click .
In the Add Files dialog box, browse to the file location that contains your generated script. Select
plotODESols.m and click Open. The Application Compiler app adds the
plotODESols function to the list of main files.
Decide whether to include the MATLAB Runtime installer in the generated application by selecting one of the two options in the Packaging Options section:
Runtime downloaded from web — Generates an installer that downloads the MATLAB Runtime and installs it along with the deployed MATLAB application
Runtime included in package — Generates an installer that includes the MATLAB Runtime installer
Customize the packaged application and its appearance by entering the following options:
Application information — Editable information about the deployed application. You can also customize the appearance of the standalone application by changing the application icon and splash screen. The generated installer uses this information to populate the installed application metadata.
Additional installer options — Options for editing the default installation path for the generated installer and selecting a custom logo.
Files required for your application to run — Additional files required by the generated application to run. The software includes these files in the generated application installer. When you add
plotODESols.m to the main file section of the toolstrip, the compiler automatically adds
myODE.m as the file required for your application to run.
Files installed for your end user — Files that are installed with your application. These files include the automatically generated
readme.txt file and the generated executable for the target platform.
Additional runtime settings — Platform-specific options for controlling the generated executable.
For details about these options, see Customize an Application (MATLAB Compiler).
To generate the packaged application, click Package in the Package section on the toolstrip. In the Save Project dialog box, specify the location in which to save the project.
In the Package dialog box, verify that Open output folder when process completes is selected.
When the deployment process is complete, the output should contain the list of things below.
for_redistribution — Folder containing the file that installs the application and the MATLAB Runtime.
for_testing — Folder containing all the artifacts created by
mcc (such as binary, header, and source files for a specific target). Use these files to test the installation.
for_redistribution_files_only — Folder containing the files required for redistributing the application. Distribute these files to users who have MATLAB or MATLAB Runtime installed on their machines.
PackagingLog.txt — Log file generated by MATLAB Compiler.
To install the standalone application, in the
for_redistribution folder, double-click the
If you want to connect to the Internet using a proxy server, click Connection Settings. Enter the proxy server settings in the provided dialog box. Click OK.
To complete the installation, follow the instructions in the installation wizard.
To run your standalone application:
Open a terminal window.
Navigate to the folder in which you installed the application.
Run the application.
Ensure that you have administrator privileges on the other machines to run and deploy the standalone application.
Choose one target machine to test the MATLAB generated standalone application.
Copy the files in the
for_testing folder to the target machine.
To test your standalone application:
Open a terminal window.
Navigate to the
Run the application.
for_redistribution_files_only folder to a file location on all target machines where MATLAB or MATLAB Runtime is installed.
Run the MATLAB generated standalone application on all target machines by using the executable in the