Find Nonzero Elements

Find nonzero elements in array

  • Library:
  • Simulink / Math Operations

  • Find Nonzero Elements block

Description

The Find Nonzero Elements block locates all nonzero elements of the input signal and returns the linear indices of those elements. If the input is a multidimensional signal, the Find Nonzero Elements block can also return the subscripts of the nonzero input elements. In both cases, you can show an output port with the nonzero input values.

The Find Nonzero Elements block outputs a variable-size signal. The sample time for any variable-size signal must be discrete. If your model does not already use a fixed-step solver, you may need to select a fixed-step solver in the Configuration Parameters dialog. For more information, see Compare Solvers and Choose a Solver.

Ports

Input

expand all

Input signal from which the block finds all nonzero elements.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Output

expand all

The Find Nonzero Elements block outputs the indices of nonzero elements as a variable-size signal. You control the data type of the output using the Output data type block parameter.

Dependencies

By default, the block outputs linear indices from the first output port. When you change the Index output format to Subscripts, the block instead provides the element indices of a two-dimension or larger signal in a subscript form. In this mode, you must specify the Number of input dimensions, and the block creates a separate output port for each dimension.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

The Find block can optionally output the values of all nonzero elements as a variable-size signal.

Dependencies

To enable this port, select Show output port for nonzero input values.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Parameters

expand all

Main

Select the output format for the indices of the nonzero input values.

  • Selecting Linear indices provides the element indices of any dimension signal in a vector form. For one dimension (vector) signals, indices correspond to the position of nonzero values within the vector. For signals with more than one dimension, the conversion of subscripts to indices is along the first dimension. You do not need to know the signal dimension of the input signal.

  • Selecting Subscripts provides the element indices of a two-dimension or larger signal in a subscript form. Because the block shows an output port for each dimension, this option requires you to specify the Number of input dimensions.

Programmatic Use

Block Parameter: IndexOutputFormat
Type: character vector
Values: 'Linear indices' | 'Subscripts'
Default: 'Linear indices'

Specify the number of dimensions for the input signal as a positive integer value from 1 to 32.

Dependencies

To enable this parameter, set Index output format to Subscripts.

Programmatic Use

Block Parameter: NumberOfInputDimensions
Type: character vector
Values: scalar
Default: '1'

Specify the indexing mode as Zero-based or One-based.

  • For Zero-based indexing, an index of 0 specifies the first element of the input vector. An index of 1 specifies the second element, and so on.

  • For One-based indexing, an index of 1 specifies the first element of the input vector. An index of 2, specifies the second element, and so on.

Programmatic Use

Block Parameter: IndexMode
Type: character vector
Values: 'Zero-based' | 'One-based'
Default: 'Zero-based'

Show or hide the output port for nonzero input values.

  • When you clear this check box (off), the block hides the output port for nonzero input values.

  • When you select this check box (on), the block displays the output port for nonzero input values. The additional output port provides values of the nonzero input elements.

Programmatic Use

Block Parameter: ShowOutputPortForNonzeroInputValues
Type: character vector
Values: 'on' | 'off'
Default: 'off'

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

This parameter is not visible unless it is explicitly set to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar or vector
Default: '-1'

Data Types

Specify the output data type.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32'| 'int64' | 'uint64'| 'fixdt(1,16)'| '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Block Characteristics

Data Types

Boolean | double | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced in R2010a