1 ## Copyright (C) 2008 Sylvain Pelissier <sylvain.pelissier@gmail.com>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{y}] =} wkeep(@var{x,l,opt})
18 ## Extract the elements of x of size l from the center, the right or the left.
21 function y = wkeep(x,l,opt = 'c')
23 if (nargin < 2|| nargin > 3); print_usage; end
27 error('l must be or equal the size of x');
32 y = x(1+floor(s):end-ceil(s));
41 error('opt must be equal to c, l or r');
45 s1 = (length(x)-l(1))./2;
46 s2 = (length(x)-l(2))./2;
48 error('For a matrix l must be a 1x2 vector');
52 y = x(1+floor(s1):end-ceil(s1),1+floor(s2):end-ceil(s2));
58 error('For a matrix l must be a 1x2 vector');
61 y=x(firstr:firstr+l(1)-1,firstc:firstc+l(2)-1);