Main Content

iterate

R2026b

Iterate over model elements

Description

iterate(arch,iterType,iterFunction) iterates over components in the architecture arch in the order specified by iterType and invokes the function specified by the function handle iterFunction on each component.

Note

This function is part of the instance programmatic interfaces that you can use to analyze the model iteratively, element-by-element. The instance refers to the element instance on which the iteration is being performed.

iterate(___,Name=Value) iterates over components in the architecture using all previous syntaxes with additional options.

iterate(___,Name=Value,additionalArgs) iterates over components in the architecture with additional options and passes all trailing arguments, specified as additionalArgs, as arguments to iterFunction.

example

Examples

collapse all

In this example, programmatically use an analysis function to compute the battery capacity for an automotive electrical system analysis. For more information on the battery sizing example, see Battery Sizing and Automotive Electrical System Analysis.

Open the battery sizing automotive analysis example and open the automotive electrical system analysis model.

openExample("systemcomposer/BatterySizingAndAutomotiveAnalysisExample")
archModel = systemcomposer.openModel("scExampleAutomotiveElectricalSystemAnalysis");

Instantiate the battery sizing class used by analysis function to store analysis results and run the analysis using the iterator.

objcomputeBatterySizing = computeBatterySizing;
iterate(archModel,"TopDown",@computeLoad,Recurse=true,objcomputeBatterySizing);

Input Arguments

collapse all

Architecture over which to iterate, specified as a systemcomposer.arch.Architecture or systemcomposer.analysis.ArchitectureInstance object.

Iteration type, specified as "PreOrder", "PostOrder", "TopDown", or "BottomUp".

  • Pre-order — Start from the top level, move to a child component, and process the subcomponents of that component recursively before moving to a sibling component.

  • Top-Down — Like pre-order, but process all sibling components before moving to their subcomponents.

  • Post-order — Start from components with no subcomponents, process each sibling, and then move to parent.

  • Bottom-up — Like post-order, but process all subcomponents at the same depth before moving to their parents.

Data Types: char | string

Iteration function, specified as a function handle to be iterated on each component.

Additional function arguments, specified as a comma-separated list of arguments to be passed to iterFunction.

Name-Value Arguments

collapse all

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: iterate(archModel,"TopDown",@computeLoad,Recurse=true,objcomputeBatterySizing)

Option to recursively iterate through model components, specified as 1 (true) to recursively iterate or 0 (false) to iterate over components only in this architecture and not navigate into the architectures of child components.

Recurse only applies to systemcomposer.arch.Architecture objects.

Data Types: logical

Option to iterate over components and architecture ports, specified as 0 (false) to only iterate over components or 1 (true) to iterate over components and architecture ports.

Data Types: logical

Option to iterate over components and connectors, specified as 0 (false) to only iterate over components or 1 (true) to iterate over components and connectors.

IncludeConnectors only applies to systemcomposer.analysis.ArchitectureInstance objects.

Data Types: logical

Option to ensure iteration order according to how components are connected from source to destination, specified as 0 (false) or 1 (true). If this option is specified as 1 (true), iteration type iterType has to be either "TopDown" or "BottomUp". If any other option is specified, the iteration type defaults to "TopDown".

FollowConnectivity only applies to systemcomposer.arch.Architecture objects.

Data Types: logical

More About

collapse all

Version History

Introduced in R2019a