Generate Code forMATLABHandle Classes and System Objects
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 frommatlab.System
. Save the code asAddOne.m
.classdefAddOne < matlab.System% ADDONE Compute an output value that increments the input by onemethods(Access=protected)% stepImpl method is called by the step methodfunctiony = stepImpl(~,x) y = x+1;endendend
Write a function that uses this System object.
functiony = testAddOne(x)%#codegenp = AddOne(); y = p.step(x);end
Generate a MEX function for this code.
codegen-reporttestAddOne-args{0}
The
-report
option instructscodegen
to generate a code generation report, even if no errors or warnings occur. The-args
option specifies that thetestAddOne
function takes one scalar double input.Click theView reportlink.
In theMATLAB苏rcepane, click
testAddOne
. To see information about the variables intestAddOne
, click theVariablestab.To view the class definition for
addOne
, in theMATLAB苏rcepane, clickAddOne
.