This example shows how to generate code for a user-defined System object™ and then view the generated code in the code generation report.
In a writable folder, create a System object, AddOne
,
which subclasses from matlab.System
. Save the code
as AddOne.m
.
classdef AddOne < matlab.System % ADDONE Compute an output value that increments the input by one methods (Access=protected) % stepImpl method is called by the step method function y = stepImpl(~,x) y = x+1; end end end
Write a function that uses this System object.
function y = testAddOne(x) %#codegen p = AddOne(); y = p.step(x); end
Generate a MEX function for this code.
codegen -report testAddOne -args {0}
The -report
option instructs codegen
to
generate a code generation report, even if no
errors or warnings occur. The -args
option specifies
that the testAddOne
function takes one scalar double
input.
Click the View report link.
In the report, on the MATLAB Code tab Functions panel,
click testAddOne
, then click the Variables tab.
You can view information about the variable p
on
this tab.
To view the class definition, on the Classes panel,
click AddOne
.