unshiftdata

Inverse of shiftdata

Syntax

y = unshiftdata(x,perm,nshifts)

Description

y = unshiftdata(x,perm,nshifts) restores the orientation of the data that was shifted with shiftdata. The permutation vector is given by perm, and nshifts is the number of shifts that was returned from shiftdata.

unshiftdata is meant to be used in tandem with shiftdata. These functions are useful for creating functions that work along a certain dimension, like filter, goertzel, sgolayfilt, and sosfilt.

Examples

collapse all

This example shifts x, a 3-by-3 magic square, permuting dimension 2 to the first column. unshiftdata shifts x back to its original shape.

Create a 3-by-3 magic square.

x = magic(3)
x = 3×3

     8     1     6
     3     5     7
     4     9     2

Shift the matrix x to work along the second dimension. The permutation vector, perm, and the number of shifts, nshifts, are returned along with the shifted matrix.

[x,perm,nshifts] = shiftdata(x,2)
x = 3×3

     8     3     4
     1     5     9
     6     7     2

perm = 1×2

     2     1

nshifts =

     []

Shift the matrix back to its original shape.

y = unshiftdata(x,perm,nshifts)
y = 3×3

     8     1     6
     3     5     7
     4     9     2

This example shows how shiftdata and unshiftdata work when you define dim as empty.

Define x as a row vector.

x = 1:5
x = 1×5

     1     2     3     4     5

Define dim as empty to shift the first nonsingleton dimension of x to the first column. shiftdata returns x as a column vector, along with perm, the permutation vector, and nshifts, the number of shifts.

[x,perm,nshifts] = shiftdata(x,[])
x = 5×1

     1
     2
     3
     4
     5

perm =

     []
nshifts = 1

Using unshiftdata, restore x to its original shape.

y = unshiftdata(x,perm,nshifts)
y = 1×5

     1     2     3     4     5

Introduced in R2012b