find
Syntax
Description
returns the elements in the model code mappings of the specified category as an array of
objects.modelElementsFound
= find(coderMapObj
,elementCategory
)
returns the elements in the model code mappings of the specified category that match
specified property and value criteria.modelElementsFound
= find(coderMapObj
,elementCategory
,Name=Value
)
Examples
Programmatically Find Code Mapping Elements of Simulink Models
Use the programmatic interface to find model elements that are related to the code mappings.
To interactively observe how your commands are reflected in the Code Mappings editor, make sure the Code Mappings editor is open with the Inports tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C.
Open the model CoderMapAPI
.
simulinkModel = "CoderMapAPI";
open_system(simulinkModel);
Retrieve the code mappings object of this model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Find input port handles of ports with ImportedExtern
storage class and input ports with ImportedExternPointer
storage class.
importedExternInportHandles = find(codeMapObj,"Inports",StorageClass="ImportedExtern")'
importedExternInportHandles = 2×1
154.0031
156.0033
importedExternPointerInportHandles = find(codeMapObj,"Inports",StorageClass="ImportedExternPointer")'
importedExternPointerInportHandles = 2×1
158.0029
160.0020
Get the names of the input ports.
importedExterInportNames = string(get_param(importedExternInportHandles,"Name"))
importedExterInportNames = 2x1 string
"in_port_1"
"in_port_2"
importedExternPointerInportNames = string(get_param(importedExternPointerInportHandles,"Name"))
importedExternPointerInportNames = 2x1 string
"in_port_3"
"in_port_4"
Generate code from the model.
evalc("slbuild(simulinkModel)");
Root-level ports with ImportedExtern
and ImportedExternPointer
storage classes are declared in the generated private header file of the model in separate sections.
Store the name of the private header file.
priv_h_file = fullfile(simulinkModel+"_grt_rtw",simulinkModel+"_private.h")
priv_h_file = "CoderMapAPI_grt_rtw/CoderMapAPI_private.h"
These are the declarations of the root-level ports in the header file:
/* Imported (extern) block signals */ extern real_T in_port_1; /* '<Root>/in_port_1' */ extern real_T in_port_2; /* '<Root>/in_port_2' */ /* Imported (extern) pointer block signals */ extern real_T *in_port_3; /* '<Root>/in_port_3' */ extern real_T *in_port_4; /* '<Root>/in_port_4' */
The storage classes of the ports match the storage classes passed to the find
function.
To open the header file, enter this command in the MATLAB Command Window.
edit(priv_h_file)
To see the ImportedExtern
inports highlighted in the model canvas and in the Code Mappings editor, enter this command:
arrayfun(@(pHandle) set_param(pHandle,Selected="on"),importedExternInportHandles);
Programmatically Find Entry-Point Functions with Function Customization Template Mapped to Model Default
Use the programmatic interface to find entry-point functions with function customization templates mapped to the model default, and remap templates to the default customization template.
To interactively observe how your commands are reflected in the Code Mappings editor, make sure the Code Mappings editor is open with the Functions tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C.
Open the model ECoderMapAPI
.
simulinkModel = "ECoderMapAPI";
open_system(simulinkModel);
Retrieve the code mappings object of the model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Use the code mappings object to find all entry-point functions with function customization template mapped to the model default. Then display the names of the functions you found.
funcObjs = find(codeMapObj,"Functions",FunctionCustomizationTemplate="Model default"); disp(funcObjs')
"Initialize" "Terminate" "Periodic:D1"
Map the function customization template of the functions you found to Default
.
setFunction(codeMapObj,funcObjs,FunctionCustomizationTemplate="Default");
Use the find
function to test if there are any entry-point functions with customization template mapped to the model default. You should get an empty list.
find(codeMapObj,"Functions",FunctionCustomizationTemplate="Model default")
ans = 0x0 empty string array
Map the function customization template of the functions you found back to model default.
setFunction(codeMapObj,funcObjs,FunctionCustomizationTemplate="Model Default");
Input Arguments
coderMapObj
— Code mapping object
CodeMapping
object
Code mapping object returned by a call to function
coder.mapping.api.get
Example: coderMapObj =
coder.mapping.api.get(bdroot)
elementCategory
— Model element category
"DataStores"
| "DataTransfers"
| ...
Model element category that you search for in the model code mappings, specified as one of these values:
"DataStores"
"DataTransfers"
"ExportedFunctions"
"Functions"
"FunctionCallers"
"Inports"
"ModelParameters"
"ModelParameterArguments"
"Outports"
"PartitionFunctions"
"PartitionUpdateFunctions"
"PeriodicFunctions"
"PeriodicUpdateFunctions"
"ResetFunctions"
"Signals"
"SimulinkFunctions"
"States"
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: find(coderMapObj,StorageClass="Bitfield")
StorageClass
— Name of storage class
"Auto"
| "ExportedGlobal"
| ...
The name of data element storage class to include in the search criteria. The storage class is either defined in the internal Embedded Coder® Dictionary of the model, or in a shared Embedded Coder Dictionary that is attached to the model.
The list of available storage classes vary depending on the specified category.
Identifier
— Code identifier
character vector | string scalar
Name that the code generator uses to identify a data element in generated code.
Applies to storage classes other than "Auto"
.
Data Types: char
| string
DefinitionFile
— C source file
character vector | string scalar
File name for a C source file that contains definitions for global data read by
data elements and external code. Applies to storage classes Const
,
ConstVolatile
, ExportToFile
, and
Volatile
.
Data Types: char
| string
FunctionCustomizationTemplate
— Name of function customization template
character vector | string scalar
Name of a function customization template for a model that is defined in the Embedded Coder Dictionary.
Data Types: char
| string
FunctionName
— Name of entry-point function
character vector | string scalar
Name of an entry-point function generated for a model.
Data Types: char
| string
GetFunction
— Name of get function
character vector | string scalar
Name of a get
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Data Types: char
| string
HeaderFile
— C header file
character vector | string scalar
File name for a C header file that contains declarations for global data read by
data elements and external code. Applies to storage classes Const
,
ConstVolatile
, Define
,
ExportToFile
, GetSet
,
ImportedDefine
, ImportFromFile
, and
Volatile
.
Data Types: char
| string
MemorySection
— Name of memory section
character vector | string scalar
Name of a memory section for a model that is defined in the Embedded Coder Dictionary.
Data Types: char
| string
Owner
— Owner of global data
character vector | string scalar
Name of the model that owns global data used by other models in the same model
hierarchy. The code generated for the owner model includes the global data definition.
Applies to storage classes Const
, ConstVolatile
,
ExportToFile
, and Volatile
.
Data Types: char
| string
PreserveDimensions
— Boolean flag indicating whether to preserve dimensions of multidimensional arrays
True
| False
When model configuration parameter Array layout is set to
Row-major
, a flag that indicates whether to preserve
dimensions of a data element that is represented in generated code as a
multidimensional array. Applies to storage classes Const
,
ConstVolatile
, ExportToFile
,
FileScope
, GetSet
,
ImportFromFile
, Localizable
, and
Volatile
.
Data Types: logical
SetFunction
— Name of set function
character string | string scalar
Name of a set
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Data Types: char
| string
StructName
— Name of structure
character vector | string scalar
Name that the code generator uses to identify the structure for a data element in
the generated code. Applies to storage classes Bitfield
and
Struct
.
Data Types: char
| string
storageClassPropertyName
— Value of storage class property
depends on property definition
Storage class property defined in the model Embedded Coder Dictionary. Values that you can specify vary depending on the storage class definition.
ReceiverService
— Name of receiver service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a receiver service interface
defined in the Embedded Coder Dictionary. Within a target environment, a component receives data from
other components by calling the target platform receiver service. To use the
dictionary default, specify "Dictionary default"
.
To configure the receiver service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Sender and Receiver Service Interfaces for Model Inports and Outports.
Data Types: char
| string
SenderService
— Name of sender service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a sender service interface
defined in the Embedded Coder Dictionary. Within a target environment, a component sends data to other
components by calling the target platform sender service. To use the dictionary
default, specify "Dictionary default"
.
To configure the sender service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Sender and Receiver Service Interfaces for Model Inports and Outports.
Data Types: char
| string
MeasurementService
— Name of measurement service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a measurement service interface
defined in the Embedded Coder Dictionary. By configuring the measurement service interface for
signals, states, and data stores, you can preserve the data in the generated code for
measurement. To use the dictionary default, specify "Dictionary
default"
. If data from the state does not need to be preserved in the
code, specify "Not measured"
.
To configure the measurement service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Measurement Service Interfaces for Signals, States, and Data Stores.
Data Types: char
| string
ParameterTuningService
— Name of parameter tuning service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a parameter tuning service
interface defined in the Embedded Coder Dictionary. To use the dictionary default, specify "Dictionary
default"
.
To configure the parameter tuning service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Parameter and Parameter Argument Tuning Service Interfaces for Model Parameters and Model Parameter Arguments.
Data Types: char
| string
ParameterArgumentTuningService
— Name of parameter argument tuning service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a parameter argument tuning
service interface defined in the Embedded Coder Dictionary. To use the dictionary default, specify "Dictionary
default"
.
To configure the parameter argument tuning service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Parameter and Parameter Argument Tuning Service Interfaces for Model Parameters and Model Parameter Arguments.
Data Types: char
| string
TimerService
— Name of timer service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a timer service interface
defined in the Embedded Coder Dictionary. To use the dictionary default, specify "Dictionary
default"
.
This property is only applicable for exported functions.
To configure the timer service interface, an Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Timer Service Interfaces.
Data Types: char
| string
Output Arguments
modelElementsFound
— Model elements found
handle array | string array
Model elements found, returned as a string array or a handle array, depending on the specified element category.
Element Category | Type of Object Returned |
---|---|
"Inports" , "Outports" , and
"States" | Block handle |
"Signals" | Port handle |
"DataStores" | Block handle |
"ModelParameters" | Model parameter name |
"ModelParameterArguments" | Model parameter argument name |
"ExportedFunctions" , "Functions" ,
"PartitionFunctions" ,
"PartitionUpdateFunctions" ,
"PeriodicFunctions" ,
"PeriodicUpdateFunctions" ,
"ResetFunctions" , and
"SimulinkFunctions" | Function name |
Version History
Introduced in R2020bR2022b: Model parameters and parameter arguments returned separately by find
function
The find
function now returns model parameter arguments separately
from model parameters.
Starting in R2022b, to return all elements in the model code mappings that are model parameter arguments, enter the following.
cm = coder.mapping.api.get("myConfigModel"); modelParamArgs = find(cm,"ModelParameterArguments");
To return all elements in the model code mappings that are model parameters, enter the following.
cm = coder.mapping.api.get("myConfigModel"); modelParams = find(cm,"ModelParameters");
In previous releases, specifying ModelParameters
as the
elementCategory
argument returned both model parameters and model
parameter arguments.
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: .
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)