Convert Fixed-Point Conversion Project to MATLAB Scripts
This example shows
how to convert a Fixed-Point Converter app project to a MATLAB® script.
You can use the -tocode
option of the fixedPointConverter
command
to create a script for fixed-point conversion. You can use the script
to repeat the project workflow in a command-line workflow. Before
you convert the project to a script, you must complete the Test step
of the fixed-point conversion process.
Prerequisites
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 Data Types Based on Simulation Ranges Using the Fixed-Point Converter App, including the Test step.
Generate the Scripts
Change to the folder that contains the project file
ex_2ndOrder_filter.prj
.Use the
-tocode
option of thefixedPointConverter
command to convert the project to a script. Use the-script
option to specify the file name for the script.fixedPointConverter -tocode ex_2ndOrder_filter -script ex_2ndOrder_filter_script.m
The
fixedPointConverter
command generates a script in the current folder.ex_2ndOrder_filter_script.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
fiaccel
command to convert the MATLAB functionex_2ndOrder_filter
to the fixed-point MATLAB functionex_2ndOrder_filter_fixpt
.
The
fiaccel
command overwrites existing files that have the same name as the generated script. If you omit the-script
option, thefiaccel
command returns the script in the Command Window.
Run Script That Generates Fixed-Point MATLAB Code
If you want to regenerate the fixed-point function, use the generated script.
Make sure that the current folder contains the entry-point function
ex_2ndOrder_filter.m
and the test bench fileex_2ndOrder_filter_test.m
.Run the script.
ex_2ndOrder_filter_script
The script generates
ex_2ndOrder_filter_fixpt.m
in the foldercodegen\ex_2ndOrder_filter\fixpt
. The variablescfg
andARGS
appear in the base workspace.