After you define input types, you can convert a MATLAB® Coder™ project
to the equivalent script of MATLAB commands. The script reproduces
the project in a configuration object and runs the codegen
command.
You can:
Move from a project workflow to a command-line workflow.
Save the project as a text file that you can share.
You can convert a project using the MATLAB Coder app or the command-line interface.
On the app toolbar, click
, and then select Convert
to script.
Specify the script name and click Save.
To convert a project to a script using the command-line interface,
use the -tocode
option of the coder
command.
The project file must be on the search path.
For example, to convert the project, myproject.prj
to
the script named myscript.m
use this command:
coder -tocode myproject -script myscript.m
The coder
command overwrites a file that
has the same name as the script. If you omit the -script
option,
the coder
command writes the script to the Command
Window.
For more information about the -tocode
option,
see coder
.
Make sure that the entry-point functions that are
arguments to codegen
in the script are on the
search path.
Run the script. For example:
myscript
The following variables appear in the base workspace.
Variable | For |
---|---|
cfg | Configuration object |
ARGS | Types of input arguments, if the project has entry-point function inputs |
ARG | Types of cell array elements, if the project has cell array
inputs. A script can reuse ARG for different cell
array elements |
GLOBALS | Types and initial values of global variables, if the project has global variables |
cfg, ARGS, ARG, and GLOBALS appear in the workspace only after you run the script. The type of configuration object depends on the project output type.
Project Output Type | Configuration Object |
---|---|
MEX Function | coder.MexCodeConfig |
C/C++ Static Library | Without an Embedded Coder® license: coder.CodeConfig With an Embedded Coder license: coder.EmbeddedCodeConfig |
C/C++ Dynamic Library | |
C/C++ Executable |
You can import the settings from the configuration object cfg
into
a project. See Share Build Configuration Settings.
For a project that includes fixed-point conversion, project to script conversion generates a pair of scripts for fixed-point conversion and fixed-point code generation. For an example, see Convert Fixed-Point Conversion Project to MATLAB Scripts.