sliceLayer
R2026bDescription
A slice layer selects elements from a specified dimension of the input data.
Creation
Description
Input Arguments
Dimension to slice, specified as a positive integer.
This argument sets the Dimension property.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Slicing indices, specified as one of these:
Vector of positive integers — The layer outputs a single array that corresponds to the specified indices. For example, for the vector
[1 3], the layer has one output that corresponds to indices1and3of the input.Cell array of vectors of positive integers — The layer outputs multiple arrays that correspond to the index vectors in the cell array. For example, for the cell array
{[1 3],[2 4]}, the layer has two outputs, where the first output corresponds to indices1and3of the input, and the second output corresponds to indices2and4of the input.
This argument sets the Indices property.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | cell
Properties
Slice
Dimension to slice, stored as a positive integer.
This property is read-only after object creation. To set this property, use the corresponding
positional input argument when you create the SliceLayer
object.
Data Types: double
Slicing indices, specified as one of these:
Vector of positive integers — The layer outputs a single array that corresponds to the specified indices. For example, for the vector
[1 3], the layer has one output that corresponds to indices1and3of the input.Cell array of vectors of positive integers — The layer outputs multiple arrays that correspond to the index vectors in the cell array. For example, for the cell array
{[1 3],[2 4]}, the layer has two outputs, where the first output corresponds to indices1and3of the input, and the second output corresponds to indices2and4of the input.
When Indices is a numeric vector, the layer has one output with the
name 'out'. When Indices is a cell array, the layer
has outputs with the names 'out1', 'out2', ...,
'outN', where N is the number of elements of
Indices. For example, the output 'outK' corresponds
to the indices Indices(K).
This property is read-only after object creation. To set this property, use the corresponding
positional input argument when you create the SliceLayer
object.
Data Types: double | cell
Layer
This property is read-only.
Number of inputs to the layer, represented as 1. This layer has a
single input only.
Data Types: double
This property is read-only.
Input name, represented as {'in'}. This layer has a single input
only.
This property is read-only.
Number of outputs from the layer, represented as a positive integer.
When Indices is a numeric vector, the layer has one output with the
name 'out'. When Indices is a cell array, the layer
has outputs with the names 'out1', 'out2', ...,
'outN', where N is the number of elements of
Indices. For example, the output 'outK' corresponds
to the indices Indices(K).
Data Types: double
This property is read-only.
Output names from the layer, represented as a cell array of character vectors.
When Indices is a numeric vector, the layer has one output with the
name 'out'. When Indices is a cell array, the layer
has outputs with the names 'out1', 'out2', ...,
'outN', where N is the number of elements of
Indices. For example, the output 'outK' corresponds
to the indices Indices(K).
Data Types: cell
Examples
Create a slice layer that selects the first and third elements from the first dimension of the layer input.
layer = sliceLayer(1,[1 3])
layer =
SliceLayer with properties:
Name: ''
Dimension: 1
Indices: [1 3]
Hyperparameters
No properties.
Algorithms
Most layers in a layer array or layer graph pass data to subsequent layers as formatted
dlarray objects.
The format of a dlarray object is a string of characters in which each
character describes the corresponding dimension of the data. The format consists of one or
more of these characters:
"S"— Spatial"C"— Channel"B"— Batch"T"— Time"U"— Unspecified
For example, you can describe 2-D image data that is represented as a 4-D array, where the
first two dimensions correspond to the spatial dimensions of the images, the third
dimension corresponds to the channels of the images, and the fourth dimension
corresponds to the batch dimension, as having the format "SSCB"
(spatial, spatial, channel, batch).
SliceLayer objects support input data of any format. The output data has
the same format as the input data.
SliceLayer objects support complex-valued input and outputs. The layer
applies the same underlying operation to complex-valued input as it does to
real-valued input. The layer outputs complex-valued data where applicable.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2026b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)