Main Content


Class: Simulink.CodeImporter
Namespace: Simulink

Add custom code and imported artifacts to MATLAB project

Since R2021a


success = addToProject(obj, ProjectFilePath)


success = addToProject(obj, ProjectFilePath), where obj is an object of class Simulink.CodeImporter or sltest.CodeImporter, adds the specified custom C/C++ code and the artifacts generated when importing custom code (using the import method) to an existing MATLAB® project. Generated artifacts include a Simulink® library and a data dictionary, and for objects of class sltest.CodeImporter, a sandbox folder. If you choose to generate a test harness and test files for the imported blocks, generated artifacts also include Simulink Test™ files (Simulink Test license required).

Input Arguments

expand all

Simulink Code Importer object, specified as a handle to a Simulink.CodeImporter object.

Name of existing MATLAB project, specified as a character vector or string scalar. The path can be a full path or a path relative to the current MATLAB folder. For addToProject to be successful, all custom code files and the Simulink library and other generated artifacts must be located in either the same folder as the MATLAB project or in direct or indirect subfolders of that folder.

Data Types: character vector | string scalar

Output Arguments

expand all

Success indicator of whether code and artifacts are added to project, returned as a logical scalar. If not successful, Simulink throws an error.

Version History

Introduced in R2021a