Convert MATLAB Coder Project to MATLAB Script - MATLAB & Simulink (original) (raw)

Main Content

You can convert a MATLAB® Coder™ project to an equivalent script of MATLAB commands. The created script uses the definitions in the MATLAB Coder project to create a configuration object, define input types, and construct acodegen command. By converting a MATLAB Coder project to a script, you can:

Converting Project to Script

To convert a project to a script, use one of these approaches:

Running the Script

Before you run the created script, make sure that the entry-point functions used by the script are on the search path. Then, call the script at the command line.

This table shows the variables that the script creates in the base workspace.

Variable Name Description
cfg Configuration object.
inputTypes Cell array that contains the input arguments for each entry point, if the project has entry-point function inputs.
childTypes Structure that contains the types of cell array elements, structure fields, and class properties, if the project has these input types. A script can reuse childTpes for different aggregate inputs.
globalVariables Cell array that contains the types and initial values of global variables, if the project has global variables.

The type of configuration object that the script creates depends on the build type of your MATLAB Coder project and on the configuration parameter Use Embedded Coder features.

Build Type Parameter Setting Created Configuration Object
MEX Any coder.MexCodeConfig
Standalone (static library, dynamic library, or executable) Use Embedded Coder features check box selected coder.EmbeddedCodeConfig
Standalone (static library, dynamic library, or executable) Use Embedded Coder features check box cleared coder.CodeConfig

You can import the settings from the configuration object cfg into a project. See Share Build Configuration Settings.

Special Cases That Generate Additional MAT File

Suppose that you convert a project file myproject.coderprj to a script myscript.m. In certain situations, the code generator can produce an additional MAT file in the same folder as the exported script. In such cases, the generated script loads the MAT file and uses the stored values to define constant inputs or constant global variables in the generated code.

This behavior happens if all of these conditions are true:

Even if all of the preceding conditions are true, you can avoid the creation of the auxiliary MAT file. Before generating the script, open the project file in the MATLAB Coder app. On the Entry Points pane, specify the constant values of the input arguments or global variables. Then, generate the script.

See Also

codegen | coder

Topics