This example shows how
to convert a MATLAB®
Coder™ project to MATLAB scripts when
the project includes automated fixed-point conversion. You can use
the -tocode
option of the coder
command
to create a pair of scripts for fixed-point conversion and fixed-point
code generation. You can use the scripts to repeat the project workflow
in a command-line workflow. Before you convert the project to the
scripts, you must complete the Test step of the
fixed-point conversion process.
This example uses the following files:
Project file ex_2ndOrder_filter.prj
Entry-point file ex_2ndOrder_filter.m
Test bench file ex_2ndOrder_filter_test.m
Generated fixed-point MATLAB file ex_2ndOrder_filter_fixpt.m
To obtain these files, complete the example Propose Fixed-Point Data Types Based on Simulation Ranges, including these steps:
Complete the Test step of the fixed-point conversion process.
Configure the project to build a C/C++ static library.
Change to the folder that contains the project file ex_2ndOrder_filter.prj
.
Use the -tocode
option
of the coder
command to
convert the project to the scripts. Use the -script
option
to specify the file name for the scripts.
coder -tocode ex_2ndOrder_filter -script ex_2ndOrder_filter_script.m
The coder
command
generates two scripts in the current folder:
ex_2ndOrder_filter_script.m
contains
the MATLAB commands to:
Create a code configuration object that has the same settings as the project.
Run the codegen
command to convert
the fixed-point MATLAB function ex_2ndOrder_filter_fixpt
to
a fixed-point C function.
The fixedPointConverter
command generates
a script in the current folder. ex_2ndOrder_filter_script_fixpt.m
contains
the MATLAB commands to:
Create a floating-point to fixed-point conversion configuration object that has the same fixed-point conversion settings as the project.
Run the codegen
command to convert the MATLAB function ex_2ndOrder_filter
to
the fixed-point MATLAB function ex_2ndOrder_filter_fixpt
.
The suffix in the script file name is the
generated fixed-point file name suffix specified by the project file.
In this example, the suffix is the default value _fixpt
.
The coder
command
overwrites existing files that have the same names as the generated
scripts. If you omit the -script
option, the coder
command
writes the scripts to the Command Window.
To run the script that generates fixed-point C code from fixed-point MATLAB code, the fixed-point MATLAB function specified in the script must be available.
Make sure that the fixed-point MATLAB function ex_2ndOrder_filter_fixpt.m
is
on the search path.
addpath c:\coder\ex_2ndOrder_filter\codegen\ex_2ndOrder_filter\fixpt
Run the script:
ex_2ndOrder_filter_script
The code generator creates a C static library with the name ex_2ndOrder_filter_fixpt
in
the folder codegen\lib\ex_2ndOrder_filter_fixpt
.
The variables cfg
and ARGS
appear
in the base workspace.
If you do not have the fixed-point MATLAB function, or if you want to regenerate it, use the script that generates the fixed-point MATLAB function from the floating-point MATLAB function.
Make sure that the current folder contains the entry-point
function ex_2ndOrder_filter.m
and the test bench
file ex_2ndOrder_filter_test.m
.
Run the script.
ex_2ndOrder_filter_script_fixpt
The code generator creates ex_2ndOrder_filter_fixpt.m
in
the folder codegen\ex_2ndOrder_filter\fixpt
. The
variables cfg
and ARGS
appear
in the base workspace.
codegen
| coder
| coder.FixptConfig