in this demonstration i'm going to use
matlab coder to generate production c
plus plus code from a matlab algorithm
we've made a number of recent
improvements to our c plus plus code
generation that i'll be highlighting
the example i'll be using represents an
oscillating system using two matlab
classes
inside of a package called my system
we'll be using the matlab coder app to
generate c
plus classes from these matlab classes
everything i'm showing can also be done
using the cogen command on the command
line
our entry point function is called
effective damping
and to tell matlab coder what the input
types to this function are we can use
our test script
run effective damping to automatically
find those
next let's reuse that same test script
to check for the absence of any runtime
errors before we generate code
i'll choose to generate a dll to share
with my colleagues and say i want c
plus code new in r2019b
is this option called interface style
that lets you choose between generating
free functions
or a class with methods we'll choose
methods and give our interface class the
name
oscillator interface
let's open the matlab coder report to
explore the generated code
on the left we see the input matlab
files and the generated c
plus files here our interface class is
exported from the dll
and has the name we specified it has a
constructor and destructor
and our entry point function was added
as a public method any matlab state like
persistent or global variables will show
up as properties in this class to make
the code multi-instance
new in r2020a matlab classes are mapped
to c
plus classes in the generated code and
r2020b
has the ability to map matlab packages
to c plus plus name spaces like we see
here
starting at r2020a the generated code
uses the coder array class to manage
dynamically allocated arrays
it has an interface similar to standard
vector it has operator overloads for
indexing
and gives you exception safe memory
deallocation
now that we've explored our generated
code let's verify its behavior
with embedded coder you can click the
verify button and
enable source code debugging
the generated code is launched in a
separate process
inputs are passed from matlab to that
process and your platform ide like
visual studio is attached to it for
debugging
breakpoints are automatically set for
you inside the interface constructor and
your entry point methods
and from here you can step through the
generated code just like any other c
plus
once we're happy with the behavior of
our generated code we can package up the
code and its dependencies into a zip
file to share with our colleagues
in the future if you'd like to move from
an app-based workflow to a command line
workflow to support systems like
automated build systems
you can click the convert to script
option this produces a matlab script
that recreates all of the
code generation settings in your matlab
coder project
we've been continually improving matlab
coder since our 2019b we've added
support for numerous matlab capabilities
including table and date time
machine learning and deep learning and
code generation support for many
signal processing toolbox functions we
strive to generate fast code that
approaches or even exceeds han
code if you're interested in c plus plus
code generation for matlab code i
suggest taking a look at the new c
plus plus capabilities in matlab coder
for 2020b
taken together they allow for the
generation of idiomatic and exception
safe c
plus code from your matlab algorithms
the example i've used here is available
in our documentation
thank you for watching