주요 콘텐츠

Convert a System to Single Precision

R2026b

This example shows how to convert a system to single precision using the Single Precision Converter. This example converts a subsystem of a double-precision model to single precision. To convert a subsystem in a model to single precision, surround the subsystem under design with Data Type Conversion blocks before opening the Single Precision Converter.

Open Model

Open the ex_corner_detection_double model and set model parameters.

open_system("ex_corner_detection_double.slx")

R = 80; C = 80;
g = fspecial('gaussian',[5 5],1.5);

The model uses a combination of double-precision, Boolean, and built-in integer data types.

Convert to Single Precision

  1. Open the Single Precision Converter. From the Simulink® Apps tab, select Single Precision Converter.

  2. Under System Under Design, select the system or subsystem to convert to single precision. For this example, select the Corner Detector subsystem. Click Convert to Single.

    Single Precision Converter toolbar with the Corner Detector subsystem selected as the system under design

    The converter first checks the system for compatibility with the conversion and changes any model settings that are incompatible. The language standard of the model must be set to C99 (ISO), and the model must use a fixed-step solver.

    The converter converts the system and lists all converted data types. The converter changes only double-precision data types. It does not convert Boolean, fixed-point, or built-in integer types to single precision.

    When the system under design contains a MATLAB® Function block, the converter creates a variant subsystem containing a generated single-precision version of the MATLAB Function block and the original MATLAB Function block.

    Variant subsystem containing the original Sobel Edge MATLAB Function block and a generated Sobel Edge_single block

    In the final stage of the conversion, the Converter verifies that the conversion was successful by updating the model.

    The Single Precision Converter shows completed conversion with compatibility results, model changes, and a table of blocks converted from double to single precision

  3. Compare the parameter memory used by the Corner Detector subsystem after converting from double to single. The app displays a bar chart of memory usage before and after single precision conversion.

    The Single Precision Converter app displays a memory usage bar chart in the lower left of the window

  4. Return to the model and update the diagram. The blocks inside the Corner Detector subsystem no longer use double-precision data types.

    The ex_corner_detector model is shown on the Simulink canvas. The data types of the signals are now displayed as single.

See Also

Topics