Mercurial > octave-nkf
view scripts/general/prepad.m @ 559:4e826edfbc56
[project @ 1994-07-25 22:18:28 by jwe]
Initial revision
author | jwe |
---|---|
date | Mon, 25 Jul 1994 22:19:05 +0000 |
parents | |
children | 3470f1e25a79 |
line wrap: on
line source
function y = prepad(x,l,c) #prepad(x,l) #Prepends zeros to the vector x until it is of length l. #prepad(x,l,c) prepends the constant c instead of zero. # #If length(x) > l, elements from the beginning of x are removed #until a vector of length l is obtained. # Author: # Tony Richardson # amr@mpl.ucsd.edu # June 1994 if(nargin == 2) c = 0; elseif(nargin<2 || nargin>3) error("usage: prepad(x,l) or prepad(x,l,c)"); endif if(is_matrix(x)) error("first argument must be a vector"); elseif(!is_scalar(l)) error("second argument must be a scaler"); endif if(l<0) error("second argument must be non-negative"); endif lx = length(x); if(lx >= l) y = x(lx-l+1:lx); else if(rows(x)>1) y = [ c*ones(l-lx,1); x ]; else y = [ c*ones(1,l-lx) x ]; endif endif endfunction