Deploy MATLAB Interface to SQLite Database Application with MATLAB Compiler
This example shows how to write a script to analyze data stored in an SQLite database using the MATLAB® interface to SQLite, and then deploy the script as a standalone application. For this example, you write code that connects to a database, imports data from the database into MATLAB, analyzes the data, and closes the database connection. Then, you deploy the code by compiling it as a standalone application using the Application Compiler (MATLAB Compiler) app, and by running the application on other machines.
The example uses the MATLAB interface to SQLite to create the database connection. Overall, the example follows the steps described in Create Standalone Application from MATLAB Function (MATLAB Compiler) and updates the steps for a standalone database application.
Create Function in MATLAB
Create a MATLAB script named
importSQLiteInterface.m and save it in a file location of your choice. The script contains the
importSQLiteInterface function, which returns the maximum product number from the data in the
productTable database table. The function connects to the SQLite database and imports all data from
productTable. Then, the function calculates the maximum product number.
function maxProdNum = importSQLiteInterface % IMPORTSQLITEINTERFACE The importSQLiteInterface function connects to an % SQLite database using the MATLAB(R) interface to SQLite, imports data % from the database into MATLAB, performs a simple data analysis, and % closes the database connection. The database contains a table named % |productTable|. %% % Create the SQLite connection |conn| to the existing SQLite database file % |tutorial.db|. The SQLite connection is an |sqlite| object. dbfile = "tutorial.db"; conn = sqlite(dbfile); %% % Import data from the |productTable| database table. tablename = "productTable"; data = sqlread(conn,tablename); %% % Determine the highest product number among products. prodNums = data.productNumber; maxProdNum = max(prodNums); %% % Close the database connection. close(conn) end
Create Standalone Application Using Application Compiler App
On the MATLAB Apps tab, on the far right of the Apps section, click the arrow to open the apps gallery. Under Application Deployment, click Application Compiler.
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 the plus sign button to add a main file.
In the Add Files dialog box, browse to the file location that contains your saved script. Select
importSQLiteInterface.mand click Open. The Application Compiler app adds the
importSQLiteInterfacefunction 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 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 specifying 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.
Files installed for your end user — Files that are installed with your application. These files include the generated
readme.txtfile 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 the option Open output folder when process completes is selected.
When the deployment process is complete, examine the generated output:
for_redistribution— Folder containing the file that installs the application and MATLAB Runtime.
for_testing— Folder containing all the artifacts created by
mcc(such as binary, JAR, 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.
Install and Run Standalone Application
To install the standalone application, double-click the
MyAppInstaller_web executable in 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.
Test Standalone Application on Target Machine
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.
Deploy Standalone Application on Target Machines
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
- Create Functions in Files
- Create Standalone Application from MATLAB Function (MATLAB Compiler)
- Customize an Application (MATLAB Compiler)
- Import Data Using MATLAB Interface to SQLite