Import custom code, functions, and types into Simulink
success = obj.import()
obj is an object of class
the specified custom code and imports it into Simulink® with default import options. If the custom code was not previously parsed or
if the custom code or the settings of
obj.CustomCode have changed since
the custom code was parsed, then the
ParseInfo property of
obj is populated or repopulated with the information resulting from the
Specify location and options for custom code, then import the code into Simulink.
%% Create code importer object obj = Simulink.CodeImporter; %% Set library file name and output folder obj.LibraryFileName = "pumpController"; obj.OutputFolder = "."; %% Set the custom code to import obj.CustomCode.InterfaceHeaders = ["pumpController.h"]; obj.CustomCode.IncludePaths = ["./include"]; obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"]; %% Parse custom code and configure function obj.parse(); fcn = obj.ParseInfo.getFunctions("Controller"); fcn.PortSpecification.ReturnArgument.Label = "control_out"; %% Import function "Controller" obj.import('Functions', ["Controller"]);
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
EntryFunctionsOnly— Option to limit import to entry-point functions
Option to limit import to entry-point functions, specified as
'Off'. If specified as
'On', only entry-point functions from the custom code, that is,
functions not called by other functions in the custom code, are imported into the
Simulink library. Otherwise, all available custom code functions are
Functions— Functions to import
Functions to import, specified as a cell array of character vectors or a string array. Specify this argument to limit import to the named custom code functions. Otherwise, all available custom code functions or all available entry-point custom code functions are imported.
Types— Additional types to import
Additional types to import, specified as a cell array of character vectors or a string array. All types required by the imported functions are imported. Additional types are defined in the interface headers.
Overwrite— Option to overwrite existing Simulink library
Option to overwrite existing Simulink library with the same name as the name specified in the
LibraryFileName property, specified as
'Off'. If set to
'Off' and there is an
existing Simulink library with the same name, custom code is imported into the existing
library without changing block settings applied in the library after previous imports
of custom code. If set to
'On', the existing library is overwritten
by the library created from the custom code import, and any prior changes to the
existing library are lost. If there is no existing Simulink library with the same name, a new library is created.
AddToProject— Option to add custom code and generated artifacts to existing MATLAB® project
Option to add custom code and generated artifacts to existing MATLAB project, specified as a file path. Artifacts include a library file for
imported functions and a data dictionary for imported types. If
obj.Options.CreateTestHarness is set to
Test™ is installed, artifacts also include a Simulink
success— Whether import is successful
Whether import is successful, specified as a logical scalar. Simulink throws an exception if the import is unsuccessful.