Getting Started with Executable Deployment

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.

Contents

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

Why deploy an executable to the Desktop

Introduction

This documentation shows how to convert MATLAB functions and Simulink models into executables using a function that has been provided by this toolbox, buildExecutable. How to deploy this executable to a robotic system is also described.

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

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

>> buildExecutable(codename)

Basic MATLAB Example

Open Example

Basic Simulink Example

Open Example