WOLFRAM SYSTEM MODELER

firstTrueIndex

Returns the index of the first true element of a Boolean vector

Wolfram Language

In[1]:=
SystemModel["Modelica.Math.BooleanVectors.firstTrueIndex"]
Out[1]:=

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Syntax

firstTrueIndex(b);

Description

Returns the index of the first true element of the Boolean vector b. If no element is true or b is an empty vector (i.e., size(b,1)=0) the function returns 0.

Example

  Boolean b1[3] = {false, false, false};
  Boolean b2[3] = {false, true, false};
  Boolean b3[4] = {false, true, false, true};
  Integer r1, r2, r3;
algorithm
  r1 = firstTrueIndex(b1);  // r1 = 0
  r2 = firstTrueIndex(b2);  // r2 = 2
  r3 = firstTrueIndex(b3);  // r3 = 2

See also

allTrue, andTrue, anyTrue, countTrue, enumerate, index, and oneTrue.

Syntax

index = firstTrueIndex(b)

Inputs (1)

b

Type: Boolean[:]

Description: Boolean vector

Outputs (1)

index

Type: Integer

Description: Index of the first true element of b