Fixed-Point Code for MATLAB Classes - MATLAB & Simulink (original) (raw)

Main Content

Automated Conversion Support for MATLAB Classes

The automated fixed-point conversion process:

Unsupported Constructs

The automated conversion process does not support:

Coding Style Best Practices

When you write MATLAB code that uses MATLAB classes:

For example, consider the counter class.

classdef Counter < handle properties Value = 0; end

properties(Constant) MAX_VALUE = 128 end

methods 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

To use the automated fixed-point conversion process, rewrite the class to have a static class that initializes the constant property MAX_VALUE and a constructor that initializes the propertyValue.

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