Reorder matrix rows or columns
Math Functions / Matrices and Linear Algebra / Matrix Operations
dspmtrx3
The Permute Matrix block reorders the rows or columns of MbyN
input matrix A
as specified by indexing input P
.
When the Permute parameter is set to Rows
,
the block uses the rows of A
to create a new matrix
with the same column dimension. Input P
is a lengthL
vector whose elements determine where each row from A
should
be placed in the LbyN output matrix.
% Equivalent MATLAB code y = [A(P(1),:) ; A(P(2),:) ; A(P(3),:) ; ... ; A(P(end),:)]
For row permutation, the block treats lengthM unoriented vector
input at the A
port as an Mby1 matrix.
When the Permute parameter is set to Columns
,
the block uses the columns of A
to create a new
matrix with the same row dimension. Input P
is
a lengthL vector whose elements determine where each column from A
should
be placed in the MbyL output matrix.
% Equivalent MATLAB code y = [A(:,P(1)) A(:,P(2)) A(:,P(3)) ... A(:,P(end))]
For column permutation, the block treats lengthN unoriented
vector input at the A
port as a 1byN matrix.
When an index value in input P
references
a nonexistent row or column of matrix A
, the block
reacts with the behavior specified by the Invalid permutation
index parameter. The following options are available:
Clip index
— Clip
the index to the nearest valid value (1 or M for row permutation,
and 1 or N for column permutation), and do not issue
an alert. Example: For a 3by7 input matrix, a column index of 9
is clipped to 7, and a row index of 2 is clipped to 1.
Clip and warn
—
Display a warning message in the MATLAB^{®} command window, and clip
the index as described above.
Generate error
—
Display an error dialog box and terminate the simulation.
When length of the permutation vector P
is
not equal to the number of rows or columns of the input matrix A
,
you can choose to get an error dialog box and terminate the simulation
by selecting Error when length of P is not equal to Permute
dimension size.
In the model below, the top Permute Matrix block places the second row of the input matrix in both the first and fifth rows of the output matrix, and places the third row of the input matrix in the three middle rows of the output matrix. The bottom Permute Matrix block places the second column of the input matrix in both the first and fifth columns of the output matrix, and places the third column of the input matrix in the three middle columns of the output matrix.
As shown in the example above, rows and columns of A
can
appear any number of times in the output, or not at all.
Method of constructing the output matrix; by permuting rows or columns of the input.
When set to Onebased
, a value of 1
in
the permutation vector P
refers to the first row
or column of the input matrix A
. When set to Zerobased
,
a value of 0
in P
refers to
the first row or column of A
.
Response to an invalid index value. Tunable (Simulink).
Option to display an error dialog box and terminate the simulation
when the length of the permutation vector P
is
not equal to the number of rows or columns of the input matrix A
.
Port  Supported Data Types 

A 

P 

Output 

Submatrix  DSP System Toolbox 
Variable Selector  DSP System Toolbox 
permute  MATLAB 
See Reorder Channels in Multichannel Signals for related information.