Main Content

Simulink.BlockDiagram.getAlgebraicLoops

Identify and analyze algebraic loops in a model

Description

example

l = Simulink.BlockDiagram.getAlgebraicLoops(mdl) identifies algebraic loops in the model mdl, opens the Algebraic Loops viewer, highlights the algebraic loops in the model, and returns information about all algebraic loops in the model as one or more AlgebraicLoop objects.

You can use the Algebraic Loops viewer to control which algebraic loops are highlighted in the model and to view information about the algebraic loops, including:

  • The number of algebraic loops in the model

  • Whether each algebraic loop is real or artificial

  • The loop ID for each algebraic loop

[l,h] = Simulink.BlockDiagram.getAlgebraicLoops(mdl) returns the handle of the figure window for the Algebraic Loops viewer.

Examples

collapse all

Open the model ex_sldemo_hydcyl.

mdl = "ex_sldemo_hydcyl";
open_system(mdl)

The model ex_sldemo_hydcyl.

Ensure that the algebraic loop diagnostic is configured to issue a warning or to not issue a diagnostic when the software detects an algebraic loop in the model. If you configure the model to issue an error, the error stops compilation of the model.

To check the diagnostic behavior configured in the model:

  1. Open the Configuration Parameters dialog box. On the Modeling tab, under Setup, click Model Settings.

  2. Select the Diagnostics pane.

  3. Check that the Algebraic loop parameter value is none or warning.

Alternatively, use the set_param function to specify the parameter value.

set_param(mdl,"AlgebraicLoopMsg","none");

The software can detect and highlight algebraic loops in the model only after the model is compiled.

Use the set_param function to issue a command that compiles the model.

set_param(mdl,"SimulationCommand","update")

Use the Simulink.BlockDiagram.getAlgebraicLoops function to detect and highlight algebraic loops in the model. The Algebraic Loops viewer opens and shows that the model contains one algebraic loop.

algLoops = Simulink.BlockDiagram.getAlgebraicLoops(mdl);

Figure Algebraic Loops in 'ex_sldemo_hydcyl' contains an object of type uigridlayout.

The algebraic loop is highlighted in the block diagram.

The model ex_sldemo_hydcyl has one algebraic loop highlighted in yellow.

The Simulink.BlockDiagram.getAlgebraicLoops function returns information about the algebraic loop as an AlgebraicLoop object.

algLoops
algLoops = 
  AlgebraicLoop with properties:

                   Model: [1x1 Simulink.BlockDiagram]
                      Id: [0 1]
    VariableBlockHandles: [2x1 double]
            BlockHandles: [9x1 double]
            IsArtificial: 0

Input Arguments

collapse all

Model to analyze for algebraic loops, specified as:

  • A string or a character vector that defines the name of the model

  • A model handle

To get the handle for the current model, you can use the function bdroot.

The model that you specify must be compiled.

Data Types: char | string

Output Arguments

collapse all

Information about algebraic loops in model, returned as an AlgebraicLoop object or an array of AlgebraicLoop objects.

The AlgebraicLoop object has these properties:

  • ModelSimulink.BlockDiagram object that represents the model

  • Id — Numeric array that uniquely identifies the algebraic loop in the model

  • VariableBlockHandles — Array of block handles for blocks that are associated with algebraic variables in the loop

  • BlockHandles — Array of block handles for all blocks in the algebraic loop

  • IsArtificial — Logical value that indicates whether the algebraic loop is artificial

Handle to figure window for Algebraic Loops viewer, returned as a matlab.ui.Figure handle.

You can use the handle for the Algebraic Loops viewer to interact with the Algebraic Loops viewer programmatically. For more information, see Figure Properties.

Version History

Introduced in R2015a