Selector
Selects specified elements from an input vector, matrix, or multidimensional signal.
Description
Block Selector extracts selected elements of the input vector or matrix based on the specified indices. The extracted signals can be grouped differently than the input signals.
Depending on the value of the Number of input dimensions parameter, the table of indexing parameters changes. Each row of the table corresponds to one of the input dimensions in the Number of input dimensions. The input signal must have no more than a certain number of dimensions specified as Number of input dimensions. For example, if the Number of input dimensions is , then the signal will be interpreted as -dimensional. For example, if a scalar (one-dimensional) is expected at the input, but the Number of input dimensions is 2
, then the scalar will be treated as two-dimensional. When configuring the block Selector for operations with multidimensional signals, the block icon changes.
Currently, processing of no more than two dimensions is supported, i.e. the correct values for the Number of input dimensions parameters are 1 and 2 .
|
For example, the signal will be treated as a 1x1 matrix.
Suppose we have an array of numbers U
and we want to select a subarray Y
of U
using some numeric value Idx1
as an index.
Suppose we have an array U
:
U = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
We want to select a subarray Y
of size 8
from U
, starting from the element with index Idx1
:
Idx1 = 3
Y = U[Idx1:Idx1+7]
This means that we select elements with indices 3
to 10
from U
. Thus, Y
will contain the following values:
Y = [3, 4, 5, 6, 7, 8, 9, 10]
Here Y
is a subarray of U
starting from the third element and including the next 7
elements after it. Idx1
defines the initial index of the second dimension, and Idx1+7
defines the final index of the second dimension.
Block Selector uses behaviour similar to the getindex function in Julia (see Indexing for details ).
|
Ports
Input
Port_1 - input signal
scalar
| vector
| matrix
Input signal from which elements for the output signal are taken.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, Uint128
, Fixed
, Bool
Support for complex numbers: Yes
IdxN - port for setting the nth index
scalar
| vector
| matrix
An external port specifying the index to select the corresponding output element. Fractional values within a block are rounded to integers.
Dependencies
To use an external index port, set the Index Option parameters to Index vector (port)
, Starting index (port)
.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, Uint128
, Fixed
Support for complex numbers: No
Parameters
Number of input dimensions - number of processed dimensions
1 (by default)
| ` integer`
Specified number of processed dimensions (N). The block configures the number of dimensions equal to the number of input dimensions specified in Number of input dimensions.
If a scalar is input and the Number of input dimensions is 2 , the block will calculate two dimensions.
|
Block parameter |
|
Value |
|
By default |
|
*Example:
The input vector has one dimension, but you want to represent it as a two-dimensional array. Suppose there is a vector with three elements, which by default is represented as one-dimensional and has dimension (3,)
.
In this case, the block uses the getindex
function with indices FirstIndices
and SecondIndices
according to the signature getindex(U, FirstIndices, SecondIndices)
:
julia> getindex(a, [1,2], :)
2x1 Matrix{Int64}:
1
2
Vector a
contains the values [1, 2, 3]
. Using the getindex
function with parameters [1, 2]
and :
, the block selects elements from vector a
on the first dimension with indices 1
and 2
, and uses all elements (represented by :
) on the second dimension. The result will be a matrix of size 2x1 containing elements of vector a
with indices 1
and 2
.
First index
Index option - method of indexing the first dimension of the input signal
Index vector (dialog) (by default)
| Select all
| Index vector (port)
| Starting index (dialog)
| Starting index (port)
| Starting and ending indices (dialog)
Determines from the dimensionality of the input signal how the elements of the signal should be indexed.
The output dimensionality can only be reduced in Index vector (dialogue) and Index vector (port) modes. This is the case when the index is specified by a number. In all other cases, the configurable dimensionality is retained. |
The block considers that the input signal has the number of dimensions equal to the value of the Number of input dimensions parameter, so the output value in most cases (if the dimension was not reduced through the Index vector mode and the index is set as a scalar) will have the number of dimensions equal to the number in the Number of input dimensions parameter. |
Index settings are available:
-
Select all
- selects all indexes by the dimension specified in Number of input dimensions. Further setting is not required.Can be represented in
getindex
notation. Select all elements on any axis is done with a colon without specifying a start and end index:
(see example above). For example:julia> getindex([1, 2, 3, 4], :) 4-element Vector{Int64}: 1 2 3 4
-
Index vector (dialogue)
- includes the Index parameters. Enter a vector of element indices. Variable size signals are not supported. Depending on the transmission of the indices (as a scalar or as a vector) depends on whether the given dimensionality is retained or reduced, which may cause dimensionality mismatches. It can be represented ingetindex
notation. Let us consider two examples:-
When the dimensionality is preserved - an index vector is introduced (even if the index is one):
julia> getindex([11 12; 21 22], [1], :) 1x2 Matrix{Int64}: 11 12 #в результате получается матрица размера (1,2)
-
When the dimensionality is reduced - the index is introduced as a scalar:
julia> getindex([11 12; 21 22], 1, :) 2-element Vector{Int64}; 11 12
-
-
Index vector (port)
- adds port IdxN. It is possible to reduce the output dimensionality. -
Starting index (dialog)
- includes parameters Index and Output size. Enter the starting index of the range of elements to select in the Index parameter and the number of elements to select in the Output size parameter. For example:The number
2
is entered as the starting index and the number4
is entered as the size. As a result, the indices will lie in the range2:5
:julia> getindex([1, 2, 3, 4, 5, 6], 2:5) 4-element Vector{Int64}: 2 3 4 5
-
Starting index (port)
- includes the Output size parameters. Enter the number of items to be selected in the Output size parameters. Adds the IdxN port. -
Starting and ending indices (dialogue)
- enables the Index parameter (dialogue box). Enter a vector of two elements ], then the selected indices will be indices from the range . For example:Enter a vector of two elements
2
and4
, which corresponds to the indices will be taken from the range2
:`4`:julia> getindex([1, 2, 3, 4, 5, 6], 2:4) 3-element Vector{Int64}: 2 3 4
*Example:
julia> a = [11 12; 21 22]
2x2 Matrix{Int64]:
11 12
21 22
Let’s select a subarray from the array a
, which includes rows with indices 1
to 1
(first row) and columns with indices 2
to 2
(second column).
The result will be a subarray of size 1x1
containing a single element located in the first row and second column of the original array a
. In this case, this element is equal to 12
:
julia> getindex(a, 1:1, 2:2)
1x1 Matrix{Int64]:
12
Block parameter |
|
Value |
|
By default |
|
Index - index of elements
1 (by default)
| ` integer`
If the Index Option parameters is Index vector (dialog)
, enter the index of each element of interest.
If the Index Option parameter is Starting index (dialog)
, enter the starting index of the range of items to be selected.
Enter, in the desired order, the indices of all the input signal elements to be present in the output signal.
Block parameter |
|
Value |
|
By default |
|
Output size - block output width
1 (by default)
| ` integer`
Sets the width of the block output signal.
Block parameter |
|
Value |
|
By default |
|
Second index
Index option - method of indexing the first dimension of the input signal
Index vector (dialog) (by default)
| Select all
| Index vector (port)
| Starting index (dialog)
| Starting index (port)
| Starting and ending indices (dialog)
Determines from the dimensionality of the input signal how the elements of the signal should be indexed.
The output dimensionality can only be reduced in Index vector (dialogue) and Index vector (port) modes. This is the case when the index is specified by a number. In all other cases, the configurable dimensionality is retained. |
The block considers that the input signal has the number of dimensions equal to the value of the Number of input dimensions parameter, so the output value in most cases (if the dimension was not reduced through the Index vector mode and the index is set as a scalar) will have the number of dimensions equal to the number in the Number of input dimensions parameter. |
Index settings are available:
-
Select all
- selects all indexes by the dimension specified in Number of input dimensions. Further setting is not required.Can be represented in
getindex
notation. Select all elements on any axis is done with a colon without specifying a start and end index:
(see example above). For example:julia> getindex([1, 2, 3, 4], :) 4-element Vector{Int64}: 1 2 3 4
-
Index vector (dialogue)
- includes the Index parameters. Enter a vector of element indices. Variable size signals are not supported. Depending on the transmission of the indices (as a scalar or as a vector) depends on whether the given dimensionality is retained or reduced, which may cause dimensionality mismatches. It can be represented ingetindex
notation. Let us consider two examples:-
When the dimensionality is preserved - an index vector is introduced (even if the index is one):
julia> getindex([11 12; 21 22], [1], :) 1x2 Matrix{Int64}: 11 12 #в результате получается матрица размера (1,2)
-
When the dimensionality is reduced - the index is introduced as a scalar:
julia> getindex([11 12; 21 22], 1, :) 2-element Vector{Int64}; 11 12
-
-
Index vector (port)
- adds port IdxN. It is possible to reduce the output dimensionality. -
Starting index (dialog)
- includes parameters Index and Output size. Enter the starting index of the range of elements to select in the Index parameter and the number of elements to select in the Output size parameter. For example:The number
2
is entered as the starting index and the number4
is entered as the size. As a result, the indices will lie in the range2:5
:julia> getindex([1, 2, 3, 4, 5, 6], 2:5) 4-element Vector{Int64}: 2 3 4 5
-
Starting index (port)
- includes the Output size parameters. Enter the number of items to be selected in the Output size parameters. Adds the IdxN port. -
Starting and ending indices (dialogue)
- enables the Index parameter (dialogue box). Enter a vector of two elements ], then the selected indices will be indices from the range . For example:Enter a vector of two elements
2
and4
, which corresponds to the indices will be taken from the range2
:`4`:julia> getindex([1, 2, 3, 4, 5, 6], 2:4) 3-element Vector{Int64}: 2 3 4
*Example:
julia> a = [11 12; 21 22]
2x2 Matrix{Int64]:
11 12
21 22
Let’s select a subarray from the array a
, which includes rows with indices 1
to 1
(first row) and columns with indices 2
to 2
(second column).
The result will be a subarray of size 1x1
containing a single element located in the first row and second column of the original array a
. In this case, this element is equal to 12
:
julia> getindex(a, 1:1, 2:2)
1x1 Matrix{Int64]:
12
Block parameter |
|
Value |
|
By default |
|
Index - index of elements
1 (by default)
| ` integer`
If the Index Option parameters is Index vector (dialog)
, enter the index of each element of interest.
If the Index Option parameter is Starting index (dialog)
, enter the starting index of the range of items to be selected.
Enter, in the desired order, the indices of all the input signal elements to be present in the output signal.
Block parameter |
|
Value |
|
By default |
|
Output size - block output width
1 (by default)
| ` integer`
Sets the width of the block output signal.
Block parameter |
|
Value |
|
By default |
|