find - Get model elements for the category of model code mappings - MATLAB (original) (raw)
Main Content
Get model elements for the category of model code mappings
Since R2020b
Syntax
Description
[modelElementsFound](#mw%5Ffe6220a9-0bc8-438f-bd27-252c326ce39a) = find([coderMapObj](#mw%5F4de9cdc7-6ad5-4b03-b922-d9fa10d7be8e),[elementCategory](#mw%5Fb6bb0461-6d0b-44d4-8f4d-ec4548e304a3))
returns the elements in the model code mappings of the specified category as an array of objects.
[modelElementsFound](#mw%5Ffe6220a9-0bc8-438f-bd27-252c326ce39a)= find([coderMapObj](#mw%5F4de9cdc7-6ad5-4b03-b922-d9fa10d7be8e),[elementCategory](#mw%5Fb6bb0461-6d0b-44d4-8f4d-ec4548e304a3),[Name=Value](#namevaluepairarguments))
returns the elements in the model code mappings of the specified category that match specified property and value criteria.
Examples
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
155.0038 157.0037
importedExternPointerInportHandles = find(codeMapObj,"Inports",StorageClass="ImportedExternPointer")'
importedExternPointerInportHandles = 2×1
159.0033 161.0024
Get the names of the input ports.
importedExterInportNames = string(get_param(importedExternInportHandles,"Name"))
importedExterInportNames = 2×1 string "in_port_1" "in_port_2"
importedExternPointerInportNames = string(get_param(importedExternPointerInportHandles,"Name"))
importedExternPointerInportNames = 2×1 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; / '/in_port_1' / extern real_T in_port_2; / '/in_port_2' */
/* Imported (extern) pointer block signals */ extern real_T in_port_3; / '/in_port_3' */ extern real_T in_port_4; / '/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.
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);
Input Arguments
Code mapping object returned by a call to functioncoder.mapping.api.get
Example: coderMapObj = coder.mapping.api.get(bdroot)
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"
"ModelVariantControls"
"ModelVariantControlArguments"
"ModelVariantVariables"
"Outports"
"PartitionFunctions"
"PartitionUpdateFunctions"
"PeriodicFunctions"
"PeriodicUpdateFunctions"
"ResetFunctions"
"Signals"
"SimulinkFunctions"
"States"
Name-Value Arguments
Specify optional pairs of arguments asName1=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")
Data Interfaces
The name of data element storage class to include in the search criteria, specified as one of these values:
"Auto"
"ExportedGlobal"
"ImportedExtern"
"ImportedExternPointer"
The list of available storage classes vary depending on the specified category.
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
Output Arguments
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 |
"ModelVariantControls" | Simulink.VariantControl object name |
"ModelVariantControlArguments" | Simulink.VariantControl model argument name |
"ModelVariantVariables" | Simulink.VariantVariable object name |
Version History
Introduced in R2020b
The find
function now supports these values for theelementCategory
argument to find Simulink.VariantControl and Simulink.VariantVariable objects in the code mapping categories.
ModelVariantControls
— FindSimulink.VariantControl
objects present in the model code mappingsModelVariantControlArguments
— FindSimulink.VariantControl
objects set as model arguments and present in the model code mappingsModelVariantVariables
— FindSimulink.VariantVariable
objects present in the model code mappings
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 theelementCategory
argument returned both model parameters and model parameter arguments.