Mercurial > hg > octave-lyh
comparison scripts/general/shift.m @ 5568:e9cde940b271
[project @ 2005-12-08 02:28:22 by jwe]
author | jwe |
---|---|
date | Thu, 08 Dec 2005 02:28:22 +0000 |
parents | 4c8a2e4e0717 |
children | 34f96dd5441b |
comparison
equal
deleted
inserted
replaced
5567:80e629357483 | 5568:e9cde940b271 |
---|---|
49 if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && | 49 if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && |
50 dim < (nd + 1)) | 50 dim < (nd + 1)) |
51 error ("shift: dim must be an integer and valid dimension"); | 51 error ("shift: dim must be an integer and valid dimension"); |
52 endif | 52 endif |
53 else | 53 else |
54 %% Find the first non-singleton dimension | 54 ## Find the first non-singleton dimension |
55 dim = 1; | 55 dim = 1; |
56 while (dim < nd + 1 && sz (dim) == 1) | 56 while (dim < nd + 1 && sz (dim) == 1) |
57 dim = dim + 1; | 57 dim = dim + 1; |
58 endwhile | 58 endwhile |
59 if (dim > nd) | 59 if (dim > nd) |
65 error ("shift: x must not be empty"); | 65 error ("shift: x must not be empty"); |
66 endif | 66 endif |
67 | 67 |
68 d = sz (dim); | 68 d = sz (dim); |
69 | 69 |
70 save_warn_empty_list_elements = warn_empty_list_elements; | 70 idx = cell (); |
71 unwind_protect | 71 for i = 1:nd |
72 warn_empty_list_elements = 0; | 72 idx {i} = 1:sz(i); |
73 endfor | |
74 if (b >= 0) | |
75 b = rem (b, d); | |
76 idx {dim} = [d-b+1:d, 1:d-b]; | |
77 elseif (b < 0) | |
78 b = rem (abs (b), d); | |
79 idx {dim} = [b+1:d, 1:b]; | |
80 endif | |
81 y = x (idx {:}); | |
73 | 82 |
74 idx = cell (); | |
75 for i = 1:nd | |
76 idx {i} = 1:sz(i); | |
77 endfor | |
78 if (b >= 0) | |
79 b = rem (b, d); | |
80 idx {dim} = [d-b+1:d, 1:d-b]; | |
81 elseif (b < 0) | |
82 b = rem (abs (b), d); | |
83 idx {dim} = [b+1:d, 1:b]; | |
84 endif | |
85 y = x (idx {:}); | |
86 | |
87 unwind_protect_cleanup | |
88 warn_empty_list_elements = save_warn_empty_list_elements; | |
89 end_unwind_protect | |
90 | 83 |
91 endfunction | 84 endfunction |