Mercurial > hg > octave-lyh
diff 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 |
line wrap: on
line diff
--- a/scripts/general/shiftdim.m +++ b/scripts/general/shiftdim.m @@ -37,9 +37,9 @@ ## @group ## x = ones (1, 2, 3); ## size (shiftdim (x, -1)) -## @result{} [2, 3, 1] +## @result{} [1, 1, 2, 3] ## size (shiftdim (x, 1)) -## @result{} [1, 1, 2, 3] +## @result{} [2, 3] ## [b, ns] = shiftdim (x); ## @result{} b = [1, 1, 1; 1, 1, 1] ## @result{} ns = 1 @@ -77,7 +77,9 @@ singleton_dims = ones (1, -n); y = reshape (x, [singleton_dims, orig_dims]); elseif (n > 0) - y = reshape (x, [orig_dims(n+1:nd), orig_dims(1:n)]); + ## We need permute here instead of reshape to shift values in a + ## compatible way. + y = permute (x, [n+1:ndims(x) 1:n]); else y = x; endif