Deploying an Executable to the Desktop

This documentation shows the workflow of generating an executable out of MATLAB and Simulink code to be placed on the desktop. This executable could be used to control your robotic platform.

In the "Running MATLAB Functions and Simulink Models on a Desktop" documentation, the workflow of running MATLAB and Simulink directly on the desktop was described.

This documentation module shows how to convert MATLAB and Simulink code into executables using a function that has been provided by this Getting Started Guide, buildExecutable. How to deploy this executable to a robotic system is also described.


Overview of Deployment

There are several different ways of deploying MATLAB and Simulink Code. This table summarizes the various deployment methods that are available for MATLAB and Simulink code to a desktop.

Table of Deployment Methods

MATLAB Simulink
Run in MATLAB or Simulink Run code in MATLAB Run code in Simulink
Desktop Deployment of Executable buildExecutable(codename) which uses codegen and packNGo buildExecutable(codename) which uses slbuild and packNGo
Desktop Algorithm Export Generate C/C++ code only, use external IDE to build Generate C/C++ code only, use external IDE to build

This module will go over the second line in this table, Desktop Deployment of an Executable using buildExecutable"

Why deploy an executable to the Desktop

An executable generated out of MATLAB and Simulink:

Steps to Build an Executable

1. Setup the Compiler

As with most code generation related workflows in MATLAB and Simulink, a compiler is necessary.

MATLAB and Simulink Coder automatically locates and uses a supported installed compiler. For the current list of supported compilers, see Supported and Compatible Compilers on the MathWorks® Web site.

You can use mex -setup to change the default compiler. See Changing Default Compiler.

To determine if your compiler is set up correctly, use the following example in the documentation:

Build an Executable Mex File

2. Build the Executable

Step 1: Check for codegen support

The codegen directive in MATLABi.e. %#codegen, checks the function to make sure that everything is supported for code generation. Add the %#codegen directive (or pragma) to your function after the function signature to indicate that you intend to generate code for the MATLAB® algorithm.

function bw = thresholdImage(img,thresholds) %#codegen
    bw = logical(... % red threshold

Adding this directive instructs the MATLAB code analyzer to help you diagnose and fix violations that would result in errors during code generation. If there are functions that are not supported for code generation, this directive will allow the MATLAB code analyzer to tell you.

Alternatively, you could use the following documentation to determine pre-emptively if a function is supported for code generation.

Features and Functions Supported for Code Generation

Step 2: Use buildExecutable

Use the buildExecutable command to generate an executable out of the MATLAB Function or Simulink Model:

>> buildExecutable(codename)

Basic Examples

Basic MATLAB Example

Open Example

Basic Simulink Example

Open Example

Other Examples

Video Acquisition and Viewing using an Executable

Learn how to acquire and view video when generating an executable

Open Example

Scheduling using an Executable

Learn how to schedule tasks when generating an executable

Open Example

Communicating using an Executable

Learn how to communicate using UDP when generating an executable

Open Example

Functions using an Executable

Learn how to use functions with system objects when generating an executable.

Open Example

Buoy Detection using an Executable

Pull these basic concepts together to implement a basic task in the RoboBoat Competition, buoy detection.

Open Example

Acoustic Acquisition

Acquire acoustic data from a DAQ

Navigate to the "Acoustic Acquisition" documentation

Remote Control

Switch a Robotic System between Autonomous and Manual Mode using an RC Remote Control

Navigate to "Remote Control" documentation

Deploying an Executable using codegen, slbuild and packNGo

The buildExecutable function uses codegen, slbuild and packNGo to create a deployable package of code for a desktop computer.

If you would prefer not to use the buildExecutable to create your executable and/or would like to learn more about the underlying functions which are used, see the documentation for Deploying and Executable using codegen, slbuild and packNGo.