Convert MATLAB Code to Fixed-Point C Code
To convert MATLAB® Code to fixed-point C Code using the MATLAB Coder™ app:
Open the MATLAB Coder app.
On the Select Source Files page, add the entry-point function from which you want to generate code.
Set Numeric Conversion to
Convert to fixed point
.Click Next to go to the Define Input Types step. The app analyzes the function for coding issues and code generation readiness. If the app identifies issues, it opens the Review Code Generation Readiness page where you can review and fix issues. If the app does not find issues, it opens the Define Input Types page.
On the Define Input Types page, specify a test file that the app can use to define the input types.
Click Next to go to the Check for Run-Time Issues step.
On the Check for Run-Time Issues page, specify a test file that calls your entry-point function. Alternatively, at the prompt, enter code that calls your entry-point function. The app generates instrumented MEX. It runs the test file or code that you specified, replacing calls to your entry-point function with calls to the generated MEX function. If the app finds issues, it provides warning and error messages. Click a message to highlight the problematic code in a window where you can edit the code.
Click Next to go to the Convert to Fixed Point step.
Propose data types based on simulation range data, derived (also known as static) range data, or both. See Propose Fixed-Point Data Types Based on Simulation Ranges and Propose Fixed-Point Data Types Based on Derived Ranges.
To convert the floating-point MATLAB code to fixed-point MATLAB code, click Convert. During fixed-point conversion, the app validates the build using the proposed fixed-point data types. See Validating Types.
Verify the behavior of the fixed-point MATLAB code. See Testing Numerics.
Click Next to go to the Generate Code step.
In the Generate dialog box, set Build source to
Fixed-Point
. Set the Build type to build a static or dynamic library, or executable. Set Language to C. Click Generate.MATLAB Coder generates fixed-point C code for your entry-point MATLAB function.