Simulink.CodeImporter.Options Class
Namespace: Simulink.CodeImporter
Specify additional import options for Simulink.CodeImporter
and
sltest.CodeImporter
classes
Since R2021a
Description
Use the Simulink.CodeImporter
class to specify options for importing custom
code beyond what is specified in the CustomCode
property of the relevant
Simulink.CodeImporter
object.
The Simulink.CodeImporter.Options
class is a handle
class.
Creation
When you create an object of class Simulink.CodeImporter
, an object of
class Simulink.CodeImporter.Options
is automatically created as the
Options
property of that object. Do not create an object of class
Simulink.CodeImporter.Options
directly.
Properties
Default size of C argument passed by pointer to function in the generated C
Caller block port specifications, specified as a character vector or string
scalar. By default, the value is set to "-1"
, meaning that the size
is inherited. A value of "1"
indicates that arguments passed by
address to functions are scalars, unless you override this setting in the SimulinkPortSpecification
corresponding to a particular function.
Data Types: char
| string
Automatic creation of test harness during import, specified as a logical 1
(true)
or 0 (false)
. Specify whether the Simulink® Code Importer should automatically create a test harness for each block in
the generated Simulink library or model (Simulink
Test™ license required).
Data Types: logical
Name by which generated Simulink library appears in Simulink Library Browser, specified as a character vector or string scalar. By
default, the value is an empty string, meaning that the generated library does not
appear in the Simulink Library Browser. If you specify a name, the Simulink Code Importer generates the file slblocks.m
as part of
the artifacts the Code Importer creates.
Example: "Controller Library"
Data Types: char
| string
Run custom code in a separate process outside of MATLAB® during model simulation, specified as logical 1 (true)
or 0 (false)
. If this property is false
, the
custom code runs in the same process as the rest of the model during simulation.
Simulations usually run faster, but run-time exceptions in the custom code can cause
MATLAB to crash. If the property is true
, custom code runs in
a separate process during model simulation, which can prevent MATLAB from crashing due to run-time exceptions in the custom code or errors in
the interface between Simulink and the custom code.
Data Types: logical
How to manage undefined functions and variables, specified as:
Value | Purpose |
---|---|
"FilterOut" | Filter out undefined functions and variables. Simulink Code Importer does not bring undefined functions and variables into the generated Simulink library or model. |
"ThrowError" | Return an error if Simulink Code Importer detects an undefined function or variable. |
"DoNotDetect" | Simulink Code Importer brings undefined functions and variables into the generated Simulink library or model, but does not automatically generate stub functions and variables equal to zero. |
"UseInterfaceOnly" | Simulink Code Importer brings undefined functions and variables into the generated Simulink library or model, and generates stub functions and variables equal to zero. |
Data Types: enum
Since R2025a
Auto
— Simulink imports the data types into the Architectural Data section of the Simulink data dictionary when any one of these conditions are met:You import custom code into an existing Simulink library and data dictionary, and architectural data section of the data dictionary is not empty.
You import custom code into a new Simulink library and data dictionary, and one of the imported types is defined under namespace.
Otherwise, the data types are imported into the Design Data section.
ArchitecturalData
— Simulink imports the data types into the Architectural Data section of the data dictionary. When you import data types that are defined under namespaces, the namespace is synchronized with the C++ Namespace code generation property of the architectural data type.DesignData
— Simulink imports the data types into the Design Data section of the data dictionary.
For more information, see Set Code Importer Options to Import Types into Architectural Data section.
To import types for an object myObj
of class
Simulink.CodeImporter
to Architectural Data
section, use:
Example: myobj.Options.DataDictionarySection="ArchitecturalData"
Data Types: enum
Examples
Create a Simulink.CodeImporter
object and set
options.
obj = Simulink.CodeImporter; obj.CustomCode.InterfaceHeaders = ["pumpController.h"]; obj.CustomCode.IncludePaths = ["./include"]; obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"]; obj.Options.LibraryBrowserName="Controller Library"; obj.Options
ans = Options with properties: PassByPointerDefaultSize: "-1" CreateTestHarness: 1 LibraryBrowserName: "Controller Library" SimulateInSeparateProcess: 0 UndefinedFunctionHandling: "FilterOut"
Since R2025a
Import types for an object myObj
of class
Simulink.CodeImporter
to Architectural Data
section.
Create an object myObj
of class
Simulink.CodeImporter
and configure the object to import types into the
Architectural Data section. Change the header file
(InterfaceHeaders
) and library browser name
(LibraryBrowserName
) per your modeling requirements.
myobj = Simulink.CodeImporter; myobj.CustomCode.InterfaceHeaders = "MyTrackerLibrary.h"; myobj.Options.DataDictionarySection="ArchitecturalData"; myobj.CustomCode.Language = "C++"; myobj.Options.LibraryBrowserName="MyArchData Library"; myobj.Options
ans = Options with properties: PassByPointerDefaultSize: "-1" CreateTestHarness: 1 LibraryBrowserName: "MyArchData Library" SimulateInSeparateProcess: 0 UndefinedFunctionHandling: FilterOut DataDictionarySection: ArchitecturalData
Parse the custom code and identify the types available to import.
s = parse(myobj); myobj.ParseInfo.AvailableTypes
ans = "topLevel::subLevel::point"
Import the parsed code.
s = import(obj);
Version History
Introduced in R2021aThe new DataDictionarySection property allows you to import data types from your custom code into the Design Data or the Architectural Data section of a Simulink data dictionary. This enhancement gives you the flexibility to organize your data within a Simulink data dictionary according to your specific requirements.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)