unshiftdata
Inverse of shiftdata
Description
restores the orientation of data y
= unshiftdata(x
,perm
,nshifts
)x
that was shifted using the shiftdata
function with permutation perm
.
Note
Use the unshiftdata
function in tandem with the shiftdata
function. These functions are useful for creating functions that
work along a certain dimension, like filter
, goertzel
, sgolayfilt
, and sosfilt
.
Examples
Permute Dimensions of a Magic Square
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
Rearrange Array to Operate on First Nonsingleton Dimension
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
Input Arguments
x
— Data
vector | matrix
Data, specified as a vector or matrix.
Data Types: single
| double
perm
— Permutation
vector
Permutation, specified as a vector.
Data Types: single
| double
nshifts
— Number of shifts
scalar
Number of shifts, specified as a scalar. nshift
is returned by
the shiftdata
function.
Data Types: single
| double
Output Arguments
y
— Restored data
vector | matrix
Restored data, returned as a vector or matrix.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2012bR2024b: unshiftdata
supports C/C++ code generation
The unshiftdata
function supports C/C++ code generation. You must
have MATLAB®
Coder™ to use this functionality.
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.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)