This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Find Nonzero Elements

Find nonzero elements in array

  • Library:
  • Simulink / Math Operations

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 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 | uint8 | uint16 | uint32 | 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 | uint8 | uint16 | uint32 | 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 | uint8 | uint16 | uint32 | 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
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'| 'fixdt(1,16)'| '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Block Characteristics

Data Types

double | single | Boolean | base integer | fixed point

Direct Feedthrough

No

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
Convert floating-point algorithms to fixed point using Fixed-Point Designer™.

Introduced in R2010a