# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

# Permute Matrix

Reorder matrix rows or columns

## Library

Math Functions / Matrices and Linear Algebra / Matrix Operations

`dspmtrx3`

## Description

The Permute Matrix block reorders the rows or columns of M-by-N 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 length-L vector whose elements determine where each row from `A` should be placed in the L-by-N output matrix.

```% Equivalent MATLAB code y = [A(P(1),:) ; A(P(2),:) ; A(P(3),:) ; ... ; A(P(end),:)] ```

For row permutation, the block treats length-M unoriented vector input at the `A` port as an M-by-1 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 length-L vector whose elements determine where each column from `A` should be placed in the M-by-L output matrix.

```% Equivalent MATLAB code y = [A(:,P(1)) A(:,P(2)) A(:,P(3)) ... A(:,P(end))] ```

For column permutation, the block treats length-N unoriented vector input at the `A` port as a 1-by-N 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 3-by-7 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.

## Examples

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.

## Parameters

Permute

Method of constructing the output matrix; by permuting rows or columns of the input.

Index mode

When set to `One-based`, a value of `1` in the permutation vector `P` refers to the first row or column of the input matrix `A`. When set to `Zero-based`, a value of `0` in `P` refers to the first row or column of `A`.

Invalid permutation index

Response to an invalid index value. Tunable (Simulink).

Error when length of P is not equal to Permute dimension size

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`.

## Supported Data Types

PortSupported Data Types

A

• Double-precision floating point

• Single-precision floating point

• Fixed point (signed and unsigned)

• Boolean

• 8-, 16-, and 32-bit signed integers

• 8-, 16-, and 32-bit unsigned integers

• Enumerated

P

• Double-precision floating point

• Single-precision floating point

• 8-, 16-, and 32-bit signed integers

• 8-, 16-, and 32-bit unsigned integers

• Enumerated

Output

• Double-precision floating point

• Single-precision floating point

• Fixed point (signed and unsigned)

• Boolean

• 8-, 16-, and 32-bit signed integers

• 8-, 16-, and 32-bit unsigned integers

• Enumerated

 Submatrix DSP System Toolbox Variable Selector DSP System Toolbox `permute` MATLAB

See Reorder Channels in Multichannel Signals for related information.