comparison scripts/general/shiftdim.m @ 5984:82a73f5dadd9

[project @ 2006-09-12 02:23:37 by jwe]
author jwe
date Tue, 12 Sep 2006 02:23:38 +0000
parents 2618a0750ae6
children 34f96dd5441b
comparison
equal deleted inserted replaced
5983:ae09df27153f 5984:82a73f5dadd9
35 ## 35 ##
36 ## @example 36 ## @example
37 ## @group 37 ## @group
38 ## x = ones (1, 2, 3); 38 ## x = ones (1, 2, 3);
39 ## size (shiftdim (x, -1)) 39 ## size (shiftdim (x, -1))
40 ## @result{} [2, 3, 1] 40 ## @result{} [1, 1, 2, 3]
41 ## size (shiftdim (x, 1)) 41 ## size (shiftdim (x, 1))
42 ## @result{} [1, 1, 2, 3] 42 ## @result{} [2, 3]
43 ## [b, ns] = shiftdim (x); 43 ## [b, ns] = shiftdim (x);
44 ## @result{} b = [1, 1, 1; 1, 1, 1] 44 ## @result{} b = [1, 1, 1; 1, 1, 1]
45 ## @result{} ns = 1 45 ## @result{} ns = 1
46 ## @end group 46 ## @end group
47 ## @end example 47 ## @end example
75 75
76 if (n < 0) 76 if (n < 0)
77 singleton_dims = ones (1, -n); 77 singleton_dims = ones (1, -n);
78 y = reshape (x, [singleton_dims, orig_dims]); 78 y = reshape (x, [singleton_dims, orig_dims]);
79 elseif (n > 0) 79 elseif (n > 0)
80 y = reshape (x, [orig_dims(n+1:nd), orig_dims(1:n)]); 80 ## We need permute here instead of reshape to shift values in a
81 ## compatible way.
82 y = permute (x, [n+1:ndims(x) 1:n]);
81 else 83 else
82 y = x; 84 y = x;
83 endif 85 endif
84 86
85 ns = n; 87 ns = n;