1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Usage
The shiftdim function is used to shift the dimensions of an
array. The general syntax for the shiftdim function is
y = shiftdim(x,n)
where x is a multidimensional array, and n is an integer. If
n is a positive integer, then shiftdim circularly shifts the
dimensions of x to the left, wrapping the dimensions around
as necessary. If n is a negative integer, then shiftdim
shifts the dimensions of x to the right, introducing
singleton dimensions as necessary. In its second form:
[y,n] = shiftdim(x)
the shiftdim function will shift away (to the left) the
leading singleton dimensions of x until the leading
dimension is not a singleton dimension (recall that a
singleton dimension p is one for which size(x,p) == 1).
Example
Here are some simple examples of using shiftdim to remove
the singleton dimensions of an array, and then restore them:
--> x = uint8(10*randn(1,1,1,3,2));
--> [y,n] = shiftdim(x);
--> n
ans =
3
--> size(y)
ans =
3 2
--> c = shiftdim(y,-n);
--> size(c)
ans =
1 1 1 3 2
--> any(c~=x)
ans =
(:,:,1,1,1) =
0
(:,:,1,1,2) =
0
Note that these operations (where shifting involves only
singleton dimensions) do not actually cause data to be
resorted, only the size of the arrays change. This is not
true for the following example, which triggers a call to
permute:
--> z = shiftdim(x,4);
Note that z is now the transpose of x
--> squeeze(x)
ans =
11 1
0 0
0 8
--> squeeze(z)
ans =
11 0 0
1 0 8
* FreeMat_Documentation
* Array_Generation_and_Manipulations
* Generated on Thu Jul 25 2013 17:17:13 for FreeMat by
doxygen_ 1.8.1.1
|