Fixed-Point Code for MATLAB Classes
Automated Conversion Support for MATLAB Classes
The automated fixed-point conversion process:
Proposes fixed-point data types based on simulation ranges for MATLAB® classes. It does not propose data types based on derived ranges for MATLAB classes.
After simulation, the MATLAB Coder™ app:
Function list contains class constructors, methods, and specializations.
Code window displays the objects used in each function.
Provides code coverage for methods.
For more information, see Viewing Information for MATLAB Classes.
Supports class methods, properties, and specializations. For each specialization of a class,
class_name, the conversion generates a separate
class_name_fixpt.mfile. For every instantiation of a class, the generated fixed-point code contains a call to the constructor of the appropriate specialization.
Supports classes that have
setmethods such as
set.PropertyName. These methods are called when properties are read or assigned. The
setmethods can be specialized. Sometimes, in the generated fixed-point code, assignment statements are transformed to function calls.
The automated conversion process does not support:
Constructors that use
Coding Style Best Practices
When you write MATLAB code that uses MATLAB classes:
Initialize properties in the class constructor.
Replace constant properties with static methods.
For example, consider the
classdef Counter < handle properties Value = 0; end properties(Constant) MAX_VALUE = 128 end methods function out = next(this) out = this.Count; if this.Value == this.MAX_VALUE this.Value = 0; else this.Value = this.Value + 1; end end end end
MAX_VALUEand a constructor that initializes the property
classdef Counter < handle properties Value; end methods(Static) function t = MAX_VALUE() t = 128; end end methods function this = Counter() this.Value = 0; end function out = next(this) out = this.Value; if this.Value == this.MAX_VALUE this.Value = 0; else this.Value = this.Value + 1; end end end end