[TOC]

shiftdim

Shift array dimensions

Usage

shiftdim(A, k)

[M, d] = shiftdim(A)

Examples

Input
a=randi(10,1,2,3)
b=shiftdim(a,1)
disp('size before shifting')
disp(size(a))
disp('size after shifting')
disp(size(b))
Output
a(:, :, 1) = 
 7.0000   7.0000

a(:, :, 2) = 
 1.0000   5.0000

a(:, :, 3) = 
 5.0000   7.0000

b = 
 7.0000   1.0000   5.0000
 7.0000   5.0000   7.0000

size before shifting
 1.0000   2.0000   3.0000

size after shifting
 2.0000   3.0000   1.0000
Input
a=randi(10,1,2,3);
% Size before shifting
size(a)
b=shiftdim(a,-2);
% Size after shifting to the right
size(b)
Output
ans =
 1.000   2.000   3.000

ans =
 1.000   1.000   1.000   2.000   3.000
Input
a = rand(1,1,2,3)
[M,d] = shiftdim(a)
Output
a(:, :, 1, 1) = 1e-1 ×
 3.9131

a(:, :, 2, 1) = 1e-1 ×
 9.5693

a(:, :, 1, 2) = 1e-1 ×
 8.5735

a(:, :, 2, 2) = 1e-1 ×
 6.5399

a(:, :, 1, 3) = 1e-1 ×
 8.9036

a(:, :, 2, 3) = 1e-1 ×
 3.4201

M = 1e-1 × 
 3.9131   8.5735   8.9036
 9.5693   6.5399   3.4201

d = 
 2.0000