Selector
Selects the specified elements from the input vector, matrix, or multidimensional array.
blockType: Selector
Path in the library:
|
Description
Block Selector extracts selected elements of an input vector, matrix, or multidimensional array based on specified indexes. The extracted signals can be grouped differently from the input signals.
Depending on the parameter value Number of input dimensions the indexing parameters table is changing. Each row of the table corresponds to one of the input dimensions in 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 Number of input dimensions equally , then the signal will be interpreted as - measured. For example, if a scalar (one-dimensional) is expected at the input, but Number of input dimensions equally 2, then the scalar will be considered as two-dimensional. When configuring the block Selector for operations with multidimensional signals, the block icon changes.
Suppose we have an array of numbers U, and we want to select a subarray Y from U using some numeric value Idx1 as an index.
Let’s say we have an array U:
U = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
We want to select a subarray Y size 8 from U, starting from the element with the index Idx1:
Idx1 = 3
Y = U[Idx1:Idx1+7]
This means that we select items with indexes from 3 before 10 from U. Thus, Y it will contain the following values:
Y = [3, 4, 5, 6, 7, 8, 9, 10]
Here Y is a subarray U starting from the third element and including the following 7 the 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 behavior similar to the function getindex in Julia (for more information, see Indexing).
|
In the parameter group Index 1 The parameters for the first index are given. The number of parameter groups depends on the number of dimensions (parameter value Number of input dimensions). The set of parameters for each index is the same, they differ only in the name for programmatic use (the number at the end of the name means the index number).
Working with indexes in Index vector mode
If for the parameter Index option the value is set Index vector (dialog) or Index vector (port) The block works as follows: if the index on any of the axes is set as a scalar, then the output signal will have a dimension in which this axis is missing. For example, the input signal has the size (a, b, c), along the axes 1 and 3 all indexes are selected from 1 before a and up c, and on the axis 2 — just the index 3 in the form of a scalar. Then the output signal will have the dimension (a, c). If on the axis 2 specify the index as an array — [3], then the output signal will have the size (a, 1, c). That is, setting the index as an array saves the configurable axis in the final dimension, and setting the index as a scalar removes the configurable axis.
Let’s look at examples for different variants of the set parameters and dimensions of the input signal.:
-
The input is a one-dimensional vector of size
(5,), the index is given as a scalar1in this case , the output is a scalar (i.e. , a signal of size()).
-
The input is a one-dimensional vector of size
(5,), the index is set as an array[1]in this case , the output is a one-dimensional vector of size(1,).
-
The input is a two-dimensional matrix of size
[3, 3], both indexes are specified as an array[1, 2]and[2]in this case , the output signal is also a two-dimensional matrix of size[2, 1].
-
The input is a two-dimensional matrix of size
[3, 3], one index is specified as an array[1, 2], and the second one is in the form of a scalar2in this case, the output signal has one dimension less than the input, that is(2,).
-
The input is a two-dimensional matrix of size
[3, 3], both indexes are given as scalars3and2in this case , we get a scalar at the output (i.e. a signal of size()).
Ports
Output
#
Y
—
output signal
scalar | vector | matrix | multidimensional array
Details
An output signal composed of selected and/or reordered elements of the input signal.
| Data types |
|
| Complex numbers support |
Yes |
Input
#
U
—
input signal
scalar | vector | matrix | multidimensional array
Details
The input signal from which elements are taken for the output signal.
| Data types |
|
| Complex numbers support |
Yes |
Parameters
Parameters
#
Number of input dimensions —
number of processed dimensions
Real number
Details
Sets the number of dimensions to process ( ) of the input signal.
Maximum number of dimensions — 32.
Example:
The input vector has one dimension, but it must be represented as a two-dimensional array. Let’s say there is a vector with three elements, which by default is represented as one-dimensional and has the dimension (3,).
In this case, the block uses the function getindex with indexes FirstIndices and SecondIndices by signature getindex(U, FirstIndices, SecondIndices):
julia> getindex(a, [1,2], :)
2x1 Matrix{Int64}:
1
2
Vector a contains values [1, 2, 3]. Using the function getindex with parameters [1, 2] and :, the block selects elements from the vector a according to the first dimension with indexes 1 and 2, and in the second dimension uses all the elements (represented by the symbol :). The result will be a matrix of size 2×1 containing the elements of the vector a with indexes 1 and 2.
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
Yes |
#
Index mode —
indexing mode
Zero-based | One-based
Details
Sets the indexing mode:
-
One-based— the first element of the input vector has the index1.Example: if the input vector contains the values
[0 5 10 20 50 100]and you need to select the element with the index3, then the output should have the value10. -
Zero-based— the first element of the input vector has the index0.Example: if the input vector contains the values
[0 5 10 20 50 100]and you need to select the element with the index3, then the output should have the value20.
| Values |
|
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
No |
#
Input port size —
width of the input signal
Integer
Details
Set the width of the block input signal for one-dimensional signals. Enter −1 to inherit from the control unit.
When working with vector strings (matrices of size on ) and vector columns (matrices of size on ) it is possible to set the number of dimensions (parameter value Number of input dimensions) equal to 1. In this case, you need to set the parameter value correctly. Input port size. You can select elements from such arrays using a single index.
|
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
Yes |
Index 1
#
Index option —
the method of indexing the first dimension of the input signal
Select all | Index vector (dialog) | Index vector (port) | Starting index (dialog) | Starting index (port) | Starting and ending indices (dialog)
Details
Determines by the dimension of the input signal how the elements of the signal should be indexed.
The output dimension can only be reduced in the following modes Index vector (dialog) and Index vector (port). This happens when the index is set as a number. In all other cases, the configurable dimension is preserved.
|
The block considers that the number of dimensions of the input signal is equal to the value of the parameter Number of input dimensions therefore , the output value in most cases (if the dimension was not reduced through modes Index vector (dialog) and Index vector (port) and the index is set by a scalar) will have a number of dimensions equal to the number in the parameter Number of input dimensions.
|
Index settings are available:
-
Select all— selects all indexes according to the specified in Number of input dimensions dimensions. No further configuration is required.It can be represented in notation
getindex. All elements along any axis are selected using a colon without specifying the start and end index.:(see the example above). For example:julia> getindex([1, 2, 3, 4], :) 4-element Vector{Int64}: 1 2 3 4 -
Index vector (dialog)— enables the parameter Index. Enter a vector of element indexes. Variable-size signals are not supported. Depending on the transfer of indexes (in the form of a scalar or in the form of a vector), it depends on whether this dimension is preserved or reduced, which may cause a mismatch of dimensions. It can be represented in notationgetindex. Let’s look at two examples:-
When the dimension is saved, a vector of indexes is entered (even if there is only one index):
julia> getindex([11 12; 21 22], [1], :) 1x2 Matrix{Int64}: 11 12 #в результате получается матрица размера (1,2) -
When the dimension is reduced, the index is entered as a scalar.:
julia> getindex([11 12; 21 22], 1, :) 2-element Vector{Int64}; 11 12
-
-
Index vector (port)— adds the IdxN port. It is possible to reduce the output dimension. -
Starting index (dialog)— includes parameters Index and Output size. Enter the initial index of the range of items to select in the parameter Index and the number of items to select in the parameter Output size. For example:The number is entered as the starting index.
2, and the number is entered as the size4. As a result, the indexes will be 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)— enables the parameter Output size. Enter the number of items to be selected in the parameter Output size. Adds the IdxN port. -
Starting and ending indices (dialog)— enables the parameter (dialog box) Index. Enter a vector of two elements ], then the selected indexes will be indexes from the range . For example:Enter a vector of two elements
2and4, which corresponds to the fact that the indexes 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
Selecting a subarray from the array a, which includes rows with indexes from 1 before 1 (first row) and columns with indexes from 2 before 2 (second column).
The result will be a subarray of size 1×1, containing a single element located in the first row and second column of the source array a. In this case, this element is equal to 12:
julia> getindex(a, 1:1, 2:2)
1x1 Matrix{Int64]:
12
| Values |
|
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
No |
#
Index —
The index of the elements
Scalar / array of real numbers
Details
If the parameter Index option equal to Index vector (dialog), enter the index of each item you are interested in.
If the parameter Index option equal to Starting index (dialog), enter the initial index of the range of items to be selected.
Enter the indexes of all the elements of the input signal that should be present in the output signal in the desired order.
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
Yes |
#
Output size —
the width of the block output signal
Scalar / array of real numbers
Details
Sets the width of the output signal of the block.
| Default value |
|
| Program usage name |
|
| Tunable |
No |
| Evaluatable |
Yes |