Mercurial > hg > octave-nkf
annotate scripts/general/shift.m @ 20368:7503499a252b stable
doc: Update docstrings to have one sentence summary as first line.
Update scripts in audio, elfun, general, geometry, and image directories.
* scripts/audio/@audioplayer/__get_properties__.m,
scripts/audio/@audioplayer/audioplayer.m, scripts/audio/@audioplayer/get.m,
scripts/audio/@audioplayer/isplaying.m, scripts/audio/@audioplayer/play.m,
scripts/audio/@audioplayer/playblocking.m, scripts/audio/@audioplayer/set.m,
scripts/audio/@audioplayer/subsasgn.m, scripts/audio/@audioplayer/subsref.m,
scripts/audio/@audiorecorder/audiorecorder.m,
scripts/audio/@audiorecorder/get.m,
scripts/audio/@audiorecorder/getaudiodata.m,
scripts/audio/@audiorecorder/getplayer.m,
scripts/audio/@audiorecorder/isrecording.m,
scripts/audio/@audiorecorder/play.m, scripts/audio/@audiorecorder/record.m,
scripts/audio/@audiorecorder/recordblocking.m,
scripts/audio/@audiorecorder/set.m, scripts/audio/@audiorecorder/stop.m,
scripts/audio/@audiorecorder/subsasgn.m,
scripts/audio/@audiorecorder/subsref.m, scripts/audio/lin2mu.m,
scripts/audio/mu2lin.m, scripts/audio/record.m, scripts/audio/sound.m,
scripts/audio/soundsc.m, scripts/audio/wavread.m, scripts/audio/wavwrite.m,
scripts/elfun/cosd.m, scripts/elfun/sind.m, scripts/elfun/tand.m,
scripts/general/accumarray.m, scripts/general/accumdim.m,
scripts/general/bitcmp.m, scripts/general/bitget.m, scripts/general/bitset.m,
scripts/general/blkdiag.m, scripts/general/cart2pol.m,
scripts/general/cart2sph.m, scripts/general/cell2mat.m,
scripts/general/celldisp.m, scripts/general/chop.m,
scripts/general/circshift.m, scripts/general/common_size.m,
scripts/general/cplxpair.m, scripts/general/cumtrapz.m,
scripts/general/dblquad.m, scripts/general/deal.m, scripts/general/del2.m,
scripts/general/display.m, scripts/general/divergence.m,
scripts/general/fieldnames.m, scripts/general/flip.m,
scripts/general/flipdim.m, scripts/general/fliplr.m, scripts/general/flipud.m,
scripts/general/gradient.m, scripts/general/interp3.m,
scripts/general/interpft.m, scripts/general/interpn.m,
scripts/general/loadobj.m, scripts/general/logspace.m,
scripts/general/methods.m, scripts/general/nargchk.m,
scripts/general/narginchk.m, scripts/general/nargoutchk.m,
scripts/general/nextpow2.m, scripts/general/nthargout.m,
scripts/general/num2str.m, scripts/general/pol2cart.m,
scripts/general/polyarea.m, scripts/general/postpad.m,
scripts/general/prepad.m, scripts/general/profile.m, scripts/general/quadgk.m,
scripts/general/quadl.m, scripts/general/quadv.m, scripts/general/randi.m,
scripts/general/rat.m, scripts/general/repmat.m, scripts/general/rot90.m,
scripts/general/rotdim.m, scripts/general/saveobj.m, scripts/general/shift.m,
scripts/general/shiftdim.m, scripts/general/sortrows.m,
scripts/general/sph2cart.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/trapz.m,
scripts/general/triplequad.m, scripts/geometry/delaunayn.m,
scripts/geometry/dsearch.m, scripts/geometry/dsearchn.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/inpolygon.m,
scripts/geometry/rectint.m, scripts/geometry/tsearchn.m,
scripts/geometry/voronoi.m, scripts/geometry/voronoin.m,
scripts/help/__unimplemented__.m, scripts/help/doc.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/lookfor.m, scripts/help/print_usage.m,
scripts/help/type.m, scripts/help/which.m, scripts/image/autumn.m,
scripts/image/bone.m, scripts/image/brighten.m, scripts/image/cmpermute.m,
scripts/image/colorcube.m, scripts/image/contrast.m, scripts/image/cool.m,
scripts/image/copper.m, scripts/image/cubehelix.m, scripts/image/flag.m,
scripts/image/gmap40.m, scripts/image/gray.m, scripts/image/gray2ind.m,
scripts/image/hot.m, scripts/image/hsv.m, scripts/image/image.m,
scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m,
scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m,
scripts/image/iscolormap.m, scripts/image/jet.m, scripts/image/lines.m,
scripts/image/ntsc2rgb.m, scripts/image/ocean.m, scripts/image/pink.m,
scripts/image/prism.m, scripts/image/rainbow.m, scripts/image/rgb2ntsc.m,
scripts/image/spinmap.m, scripts/image/spring.m, scripts/image/summer.m,
scripts/image/white.m, scripts/image/winter.m:
Update docstrings to have one sentence summary as first line.
Re-structure to have line lengths <= 80 chars.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 May 2015 09:36:20 -0700 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1995-2015 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
2539 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
2539 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2539 | 18 |
3369 | 19 ## -*- texinfo -*- |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} shift (@var{x}, @var{b}) |
4862 | 21 ## @deftypefnx {Function File} {} shift (@var{x}, @var{b}, @var{dim}) |
3369 | 22 ## If @var{x} is a vector, perform a circular shift of length @var{b} of |
23 ## the elements of @var{x}. | |
3426 | 24 ## |
3369 | 25 ## If @var{x} is a matrix, do the same for each column of @var{x}. |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20038
diff
changeset
|
26 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20038
diff
changeset
|
27 ## If the optional @var{dim} argument is given, operate along this dimension. |
3369 | 28 ## @end deftypefn |
2539 | 29 |
30 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> | |
31 ## Created: 14 September 1994 | |
32 ## Adapted-By: jwe | |
33 | |
4862 | 34 function y = shift (x, b, dim) |
2539 | 35 |
4862 | 36 if (nargin != 2 && nargin != 3) |
6046 | 37 print_usage (); |
2539 | 38 endif |
39 | |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
40 if (numel (x) < 1) |
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
41 error ("shift: X must not be empty"); |
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
42 elseif (! (isscalar (b) && b == fix (b))) |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
43 error ("shift: B must be an integer"); |
2539 | 44 endif |
45 | |
4862 | 46 nd = ndims (x); |
47 sz = size (x); | |
48 | |
49 if (nargin == 3) | |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
50 if (!(isscalar (dim) && dim == fix (dim)) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10690
diff
changeset
|
51 || !(1 <= dim && dim <= nd)) |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
52 error ("shift: DIM must be an integer and a valid dimension"); |
4862 | 53 endif |
54 else | |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
55 ## Find the first non-singleton dimension. |
12674
9493880928c8
Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 (dim = find (sz > 1, 1)) || (dim = 1); |
4862 | 57 endif |
58 | |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
59 d = sz(dim); |
4862 | 60 |
12676
2783fa95cab7
Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents:
12674
diff
changeset
|
61 idx = repmat ({':'}, nd, 1); |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
62 if (b > 0) |
5568 | 63 b = rem (b, d); |
7208 | 64 idx{dim} = [d-b+1:d, 1:d-b]; |
5568 | 65 elseif (b < 0) |
66 b = rem (abs (b), d); | |
7208 | 67 idx{dim} = [b+1:d, 1:b]; |
5568 | 68 endif |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
69 |
7208 | 70 y = x(idx{:}); |
4369 | 71 |
7411 | 72 endfunction |
2539 | 73 |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
74 |
7411 | 75 %!test |
76 %! a = [1, 2, 3]; | |
77 %! b = [4, 5, 6]; | |
78 %! c = [7, 8, 9]; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
79 %! |
7411 | 80 %! r = [a, b, c]; |
81 %! m = [a; b; c]; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 %! |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %! assert (shift (r, 0), r); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
84 %! assert (shift (r, 3), [c, a, b]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 %! assert (shift (r, -6), [c, a, b]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
86 %! assert (shift (r, -3), [b, c, a]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 %! assert (shift (m, 1), [c; a; b]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 %! assert (shift (m, -2), [c; a; b]); |
7411 | 89 |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
90 ## Test input validation |
13278
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
91 %!error shift () |
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
92 %!error shift (1, 2, 3, 4) |
04edb15d7966
shift.m: Clean up code and add more tests
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
93 %!error shift ([], 1) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %!error shift (ones (2), ones (2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %!error shift (ones (2), 1.5) |
13296
27da11c63d98
shift.m: Add validation tests for dimension argument
Rik <octave@nomad.inbox5.com>
parents:
13292
diff
changeset
|
96 %!error shift (1, 1, 1.5) |
27da11c63d98
shift.m: Add validation tests for dimension argument
Rik <octave@nomad.inbox5.com>
parents:
13292
diff
changeset
|
97 %!error shift (1, 1, 0) |
27da11c63d98
shift.m: Add validation tests for dimension argument
Rik <octave@nomad.inbox5.com>
parents:
13292
diff
changeset
|
98 %!error shift (1, 1, 3) |
7411 | 99 |