addElement
Description
creates a structElementObj
= addElement(StructTypeObj
,elementName
)Simulink.dictionary.archdata.StructElement
object with the name
elementName
and adds the element to the struct type object
StructTypeObj
.
Examples
Configure Struct Elements of a StructType
To configure struct elements of a struct type, use the addElement
,
getElement
,
and removeElement
functions.
In this example, the dictionary MyInterfaces.sldd
contains one
struct type.
archDataObj = Simulink.dictionary.archdata.open("MyInterfaces.sldd")
archDataObj = ArchitecturalData with properties: DictionaryFileName: 'MyInterfaces.sldd' Interfaces: [0×0 Simulink.dictionary.archdata.DataInterface] DataTypes: [1×1 Simulink.dictionary.archdata.StructType] Constants: [0×0 Simulink.dictionary.archdata.Constant]
Get the struct type object using the getDataType
function. The struct type object contains two struct element
objects.
structTypeObj = getDataType(archDataObj,"structType1")
structTypeObj = StructType with properties: Name: 'structType1' Description: '' Elements: [1×2 Simulink.dictionary.archdata.StructElement] Owner: [1×1 Simulink.dictionary.ArchitecturalData]
To create a struct element object and add it to the struct type, use the addElement
function.
structElemObj3 = addElement(structTypeObj,"structElement3")
structElemObj3 = StructElement with properties: Name: 'structElement3' Type: [1×1 Simulink.dictionary.archdata.ValueType] Description: '' Dimensions: '1' Owner: [1×1 Simulink.dictionary.archdata.StructType]
To access an existing function element, use the getElement
function.
structElemObj2 = getElement(structTypeObj,"structElement2")
structElemObj2 = StructElement with properties: Name: 'structElement2' Type: [1×1 Simulink.dictionary.archdata.ValueType] Description: '' Dimensions: '1' Owner: [1×1 Simulink.dictionary.archdata.StructType]
To remove a struct element from a struct type, use the removeElement
function.
removeElement(structTypeObj,"structElement1")
The struct type object now contains only two struct elements,
structElement2
and structElement3
structTypeObj.Elements(1)
ans = StructElement with properties: Name: 'structElement2' Type: [1×1 Simulink.dictionary.archdata.ValueType] Description: '' Dimensions: '1' Owner: [1×1 Simulink.dictionary.archdata.StructType]
structTypeObj.Elements(2)
ans = StructElement with properties: Name: 'structElement3' Type: [1×1 Simulink.dictionary.archdata.ValueType] Description: '' Dimensions: '1' Owner: [1×1 Simulink.dictionary.archdata.StructType]
Input Arguments
StructTypeObj
— Struct type object
Simulink.dictionary.archdata.StructType
object
Struct type object, specified as a
Simulink.dictionary.archdata.StructType
object.
elementName
— Name of struct element
character vector | string scalar
Name of struct element, specified as a character vector or string scalar.
Data Types: char
| string
Output Arguments
structElementObj
— Struct element
Simulink.dictionary.archdata.StructElement
object
Struct element, returned as a Simulink.dictionary.archdata.StructElement
object.
Version History
Introduced in R2023b
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)