Convert codegen Command to Equivalent MATLAB Coder Project - MATLAB & Simulink (original) (raw)

Main Content

You can use the codegen command with the-toproject option to convert a codegen command to an equivalent MATLAB® Coder™ project file. You can then generate code from the project file by using another codegen command or the MATLAB Coder app.

For example, to convert a codegen command with input argumentsinput_arguments to the project file myProject.prj, run:

codegen input_arguments -toproject myProject.prj

Input arguments to codegen include:

You can also use the -toproject option to convert an incompletecodegen command to a project file. For example, to create a project file myProjectTemplate.prj that contains only the code generation parameters stored in the configuration object cfg, run:

codegen -config cfg -toproject myProjectTemplate.prj

myProjectTemplate.prj does not contain specifications of entry-point functions or input types. So, you cannot generate code from this project file. You can open myProjectTemplate.prj in the MATLAB Coder app and use it as a template to create full project files that you can use to generate code.

Note

Running the codegen command with the-toproject option does not generate code. It creates only the project file.

Example: Convert a Complete codegen Command to a Project File

Define a MATLAB function, myadd, that returns the sum of two values.

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

Create a coder.CodeConfig object for generating a static library. Set TargetLang to 'C++'.

cfg = coder.config('lib'); cfg.TargetLang = 'C++';

At the MATLAB command line, create and run a codegen command. Specifymyadd as the entry-point function. Specify the inputs tomyadd as variable-size matrices of type double whose dimensions are unbounded. Specify cfg as the code configuration object. Include the -toproject option to convert thecodegen command to an equivalent MATLAB Coder project file with name myadd_project.prj.

codegen -config cfg myadd -args {coder.typeof(1,[Inf,Inf]),coder.typeof(1,[Inf,Inf])} -toproject myadd_project.prj

Project file 'myadd_project.prj' was successfully created. Open Project

The code generator creates the project file myadd_project.prj in the current working folder. Running codegen with the-toproject option does not generate code. It creates only the project file.

Generate code from myadd_project.prj by using anothercodegen command.

codegen myadd_project.prj

The code generator produces a C++ static library function myadd in the _`work`_\codegen\lib\myadd folder, where_`work`_ is your current working directory.

Example: Convert an Incomplete codegen Command to a Template Project File

Create a coder.CodeConfig object for generating a static library. Set TargetLang to 'C++'.

cfg = coder.config('lib'); cfg.TargetLang = 'C++';

At the MATLAB command line, create and run a codegen command. Specifycfg as the code configuration object. Include the-toproject option to convert the codegen command to an equivalent MATLAB Coder project file with name myProjectTemplate.prj.

codegen -config cfg -toproject myProjectTemplate.prj

Project file 'myProjectTemplate.prj' was successfully created. Open Project

You can now open myProjectTemplate.prj in the MATLAB Coder app and use it as a template to create full project files that you can use to generate code.

Limitations

When you use the codegen command with the-toproject option, these limitations apply:

See Also

codegen