Main Content

Generate Fixed-Point MATLAB Code for Multiple Entry-Point Functions

When your end goal is to generate fixed-point C/C++ library functions, generating a single C/C++ library for more than one entry-point MATLAB® function allows you to:

  • Create C/C++ libraries containing multiple, compiled MATLAB files to integrate with larger C/C++ applications. Generating C/C++ code requires a MATLAB Coder™ license.

  • Share code efficiently between library functions.

  • Communicate between library functions using shared memory.

Note

If any of the entry-point functions in a project share memory (for example, persistent data), an error will occur. In this case, you should rewrite your code to avoid invoking functions with persistent data from multiple entry-points.

Example 1. Convert Two Entry-Point Functions to Fixed-Point Using the Fixed-Point Converter App

In this example, you convert two entry-point functions, ep1 and ep2, to fixed point.

  1. In a local writable folder, create the functions ep1.m and ep2.m.

    function y = ep1(u) %#codegen
    y = u;
    end
    function y = ep2(u, v) %#codegen
    y = u + v;
    end

  2. In the same folder, create a test file, ep_tb.m, that calls both functions.

    % test file for ep1 and ep2
    u = 1:100;
    v = 5:104;
    z = ep1(u);
    y = ep2(v,z);
    

  3. From the apps gallery, open the Fixed-Point Converter app.

  4. To add the first entry-point function, ep1, to the project, on the Select Source Files page, browse to the ep1 file, and click Open.

    By default, the app uses the name of the first entry-point function as the name of the project.

  5. Click Add Entry-Point Function and add the second entry-point function, ep2. Click Next.

  6. On the Define Input Types page, enter a test file that exercises your two entry-point functions. Browse to select the ep_tb file. Click Autodefine Input Types.

  7. Click Next. The app generates an instrumented MEX function for your entry-point MATLAB function. On the Convert to Fixed-Point page, click Simulate to simulate the entry-point functions, gather range information, and get proposed data types.

  8. Click Convert.

    The entry-point functions ep1 and ep2 convert to fixed point. The Output Files pane lists the generated fixed-point and wrapper files for both entry-point functions.

  9. Click Next. The Finish Workflow page contains the project summary. The generated Fixed-Point Conversion Report contains the reports for both entry-point functions. The app stores the generated files in the subfolder codegen/ep1/fixpt.