Main Content

Convert MATLAB Code to Fixed-Point C Code

To convert MATLAB® Code to fixed-point C Code using the MATLAB Coder™ app:

  1. Open the MATLAB Coder app.

  2. On the Select Source Files page, add the entry-point function from which you want to generate code.

  3. Set Numeric Conversion to Convert to fixed point.

  4. 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.

  5. On the Define Input Types page, specify a test file that the app can use to define the input types.

  6. Click Next to go to the Check for Run-Time Issues step.

  7. 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.

  8. Click Next to go to the Convert to Fixed Point step.

  9. 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.

  10. 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.

  11. Verify the behavior of the fixed-point MATLAB code. See Testing Numerics.

  12. Click Next to go to the Generate Code step.

  13. 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.

Related Topics