Submatrix
Select subset of elements (submatrix) from matrix input
Libraries:
Simulink /
Matrix Operations
Description
The Submatrix block extracts a contiguous submatrix, y,
from the M-by-N input matrix u
.
For more information about selecting the rows and columns to extract, see Range Specification Options.
Examples
Extract 3-by-2 Submatrix from Input Signal
This example shows how to use the Submatrix block to extract a 3-by-2 submatrix from the lower-right corner of a 5-by-7 input matrix. The following figure illustrates the operation of the Submatrix block with a 5-by-7 input matrix of random integer elements, randi([0 9],5,7)
.
Here are the settings used for the Submatrix
block in this example.
There are often several possible parameter combinations that you can use to select the same submatrix from the input. For example, in the case of a 5-by-7 input matrix, instead of specifying Last
for Ending column, you could select the same submatrix by specifying:
Ending column =
Index
Ending column index =
7
Open and simulate the model. You can see that the 3-by-2 submatrix from the lower-right corner of a 5-by-7 input matrix has been extracted.
Ports
Input
Port_1 — Input signal
vector | matrix
Input signal, from which the block extracts the specified submatrix.
This block supports Simulink® virtual buses.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Output
Port_1 — Selected submatrix
vector | matrix
Submatrix selected from the input signal. The data type of the output is the same as the input.
This block supports Simulink virtual buses.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Parameters
For more information about selecting the subset of elements to form the submatrix, see Range Specification Options.
Row span — Range of rows
All rows
(default) | One row
| Range of rows
The range of input rows to be retained in the output.
Row — First row of output
First
(default) | Index
| Offset from last
| Last
| Offset from middle
| Middle
The input row to be used as the first and only row of the output.
Dependencies
To enable this parameter, set Row span to
One row
.
Starting row — First row of output
First
(default) | Index
| Offset from last
| Last
| Offset from middle
| Middle
The input row to be used as the first row of the output.
Dependencies
To enable this parameter, set Row span to
Range of rows
.
Row index — Index of first row
1
(default) | positive integer
The index of the input row to be used as the first and only row of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Row span to
One row
and Row to
Index
.
Starting row index — Index of first row
1
(default) | positive integer
The index of the input row to be used as the first row of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Row span to
Range of rows
and Starting
row to Index
.
Row offset — Offset of first row
1
(default) | positive integer
The offset of the input row to be used as the first and only row of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Row span to
One row
and Row to
Offset from last
or Offset
from middle
.
Starting row offset — Offset of first row
1
(default) | positive integer
The offset of the input row to be used as the first row of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Row span to
Range of rows
and Starting
row to Offset from last
or
Offset from middle
.
Ending row — Last row
Last
(default) | Index
| Offset from last
| Offset from middle
| Middle
The input row to be used as the last row of the output.
Dependencies
To enable this parameter, set Row span to
Range of rows
and set Starting
row to any value except
Last
.
Ending row index — Index of last row
1
(default) | positive integer
The index of the input row to be used as the last row of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Ending row to
Index
.
Ending row offset — Offset of last row
1
(default) | positive integer
The offset of the input row to be used as the last row of the output.
Dependencies
To enable this parameter, set Ending row to
Offset from middle
or Offset
from last
.
Column span — Range of input columns
All columns
(default) | One column
| Range of columns
The range of input columns to be retained in the output.
Column — First column
First
(default) | Index
| Offset from last
| Last
| Offset from middle
| Middle
The input column to be used as the first and only column of the output.
Dependencies
To enable this parameter, set Column span to
One column
.
Starting column — First column
First
(default) | Index
| Offset from last
| Last
| Offset from middle
| Middle
The input column to be used as the first column of the output.
Dependencies
To enable this parameter, set Column span to
Range of columns
.
Starting column index — Index of first column
1
(default) | positive integer
The index of the input column to be used as the first column of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Column span to
Range of columns
and Starting
column to Index
.
Column index — Index of first column
1
(default) | positive integer
The index of the input column to be used as the first and only column of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Column span to
One column
and
Column to
Index
.
Column offset — Offset of first column
1
(default) | positive integer
The offset of the input column to be used as the first and only column of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Column span to
One column
and
Column to Offset from
last
or Offset from
middle
.
Starting column offset — Offset of first column
1
(default) | positive integer
The offset of the input column to be used as the first column of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Column span to
Range of columns
and Starting
column to Offset from last
or
Offset from middle
.
Ending column — Last column
Last
(default) | Index
| Offset from last
| Offset from middle
| Middle
The input column to be used as the last column of the output.
Dependencies
To enable this parameter, set Column span to
Range of columns
and set
Starting column to any value except
Last
.
Ending column index — Index of last column
1
(default) | positive integer
The index of the input column to be used as the last column of the output, specified as an integer greater than or equal to one.
Dependencies
To enable this parameter, set Ending column to
Index
.
Ending column offset — Offset of last column
1
(default) | positive integer
The offset of the input column to be used as the last column of the output.
Dependencies
To enable this parameter, set Ending column to
Offset from middle
or Offset
from last
.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
Range Specification Options
The block treats length-M unoriented vector input as an
M-by-1
matrix. The Row
span parameter provides three options for specifying the range of
rows in u
to be retained in submatrix output
y
:
All rows
Specifies that
y
contains all M rows ofu
.One row
Specifies that
y
contains only one row fromu
. SelectingOne row
enables the Row parameter to allow selection of the desired row.Range of rows
Specifies that
y
contains a range of rows fromu
. SelectingRange of rows
enables the Starting row and Ending row parameters to allow selection of the desired range of rows.
The Column span parameter contains a corresponding set of
three options for specifying the range of columns in u
to be
retained in submatrix y
: All columns
,
One column
, or Range of
columns
. The One column
option enables
the Column parameter, and Range of
columns
options enable the Starting column
and Ending column parameters.
When you select One row
or Range of
rows
from the Row span parameter, you specify
the desired row or range of rows in the Row parameter, or the
Starting row and Ending row
parameters. Similarly, when you select One column
or
Range of columns
from the Column
span parameter, you specify the desired column or range of columns in
the Column parameter, or the Starting
column and Ending column parameters.
The Row, Column, Starting row, or Starting column can be specified in six ways:
First
For rows, this specifies that the first row of
u
should be used as the first row ofy
. When all columns are to be included, this is equivalent toy(1,:) = u(1,:)
.For columns, this specifies that the first column of
u
should be used as the first column ofy
. When all rows are to be included, this is equivalent toy(:,1) = u(:,1)
.Index
For rows, this specifies that the row of
u
,firstrow
, forward-indexed by the Row index parameter or the Starting row index parameter, should be used as the first row ofy
. When all columns are to be included, this is equivalent toy(1,:) = u(firstrow,:)
.For columns, this specifies that the column of
u
, forward-indexed by the Column index parameter or the Starting column index parameter,firstcol
, should be used as the first column ofy
. When all rows are to be included, this is equivalent toy(:,1) = u(:,firstcol)
.Offset from last
For rows, this specifies that the row of
u
offset from row M by the Row offset or Starting row offset parameter,firstrow
, should be used as the first row ofy
. When all columns are to be included, this is equivalent toy(1,:) = u(M-firstrow,:)
.For columns, this specifies that the column of
u
offset from column N by the Column offset or Starting column offset parameter,firstcol
, should be used as the first column ofy
. When all rows are to be included, this is equivalent toy(:,1) = u(:,N-firstcol)
.Last
For rows, this specifies that the last row of
u
should be used as the only row ofy
. When all columns are to be included, this is equivalent toy = u(M,:)
.For columns, this specifies that the last column of
u
should be used as the only column ofy
. When all rows are to be included, this is equivalent toy = u(:,N)
.Offset from middle
When you select this option, the block selects the first row or column of the output
y
by adding the specified offset to the middle row or column of the inputu
. When the number, X, of input rows or columns is even, the block defines the middle as X/2 +1. When the number of input rows or columns is odd, the block defines the middle asceil
(X/2).When all columns are to be included, the following code defines the starting row:
y(1,:) = u(MiddleRow+Offset,:)
, whereOffset
is the value of the Row offset or Starting row offset parameter. When all rows are to be included, the following code defines the starting column:y(1,:) = u(:,MiddleColumn+Offset)
, whereOffset
is the value of the Column offset or Starting column offset parameter.Middle
When you select this option, the block uses the middle row or column of the input
u
as the first row or column of the outputy
. When the number, X, of input rows or columns is even, the block defines the middle as X/2 +1. When the number of input rows or columns is odd, the block defines the middle asceil
(X/2).When all columns are to be included, the following code defines the starting row:
y = u(MiddleRow,:)
. When all rows are to be included, the following code defines the starting column:y = u(:,MiddleColumn)
.
The Ending row or Ending column can similarly be specified in five ways:
Index
For rows, this specifies that the row of
u
forward-indexed by the Ending row index parameter,lastrow
, should be used as the last row ofy
. When all columns are to be included, this is equivalent toy(end,:) = u(lastrow,:)
.For columns, this specifies that the column of
u
forward-indexed by the Ending column index parameter,lastcol
, should be used as the last column ofy
. When all rows are to be included, this is equivalent toy(:,end) = u(:,lastcol)
.Offset from last
For rows, this specifies that the row of
u
offset from row M by the Ending row offset parameter,lastrow
, should be used as the last row ofy
. When all columns are to be included, this is equivalent toy(end,:) = u(M-lastrow,:)
.For columns, this specifies that the column of
u
offset from column N by the Ending column offset parameter,lastcol
, should be used as the last column ofy
. When all rows are to be included, this is equivalent toy(:,end) = u(:,N-lastcol)
.Last
For rows, this specifies that the last row of
u
should be used as the last row ofy
. When all columns are to be included, this is equivalent toy(end,:) = u(M,:)
.For columns, this specifies that the last column of
u
should be used as the last column ofy
. When all rows are to be included, this is equivalent toy(:,end) = u(:,N)
.Offset from middle
When you select this option, the block selects the last row or column of the output
y
by adding the specified offset to the middle row or column of the inputu
. When the number, X, of input rows or columns is even, the block defines the middle as X/2 +1. When the number of input rows or columns is odd, the block defines the middle asceil
(X/2).When all columns are to be included, the following code defines the ending row:
y(end,:) = u(MiddleRow+Offset,:)
, whereOffset
is the value of the Ending row offset parameter. When all rows are to be included, the following code defines the ending column:y(:,end) = u(:,MiddleColumn+Offset)
, whereOffset
is the value of the Ending column offset parameter.Middle
When you select this option, the block uses the middle row or column of the input
u
as the last row or column of the outputy
. When the number, X, of input rows or columns is even, the block defines the middle as X/2 +1. When the number of input rows or columns is odd, the block defines the middle asceil
(X/2).When all columns are to be included, the following code defines the ending row:
y(end,:) = u(MiddleRow,:)
. When all rows are to be included, the following code defines the ending column:y(:,end) = u(:,MiddleColumn)
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on the memcpy
or
memset
function (string.h
) under certain
conditions.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006aR2021b: Create Submatrix Block Moved to Simulink Matrix Operations Library
The Submatrix block has been moved from the DSP System Toolbox > Math Functions > Matrices and Linear Algebra > Matrix Operations library to the Simulink > Matrix Operationslibrary. All existing models continue to work.
See Also
Blocks
- Variable Selector (DSP System Toolbox) | Reshape | Selector
Functions
Topics
- Split Multichannel Signals into Several Multichannel Signals (DSP System Toolbox)
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)