comparison scripts/general/postpad.m @ 1337:52a3f38cbfeb

[project @ 1995-08-25 02:00:18 by jwe]
author jwe
date Fri, 25 Aug 1995 02:16:01 +0000
parents 3470f1e25a79
children 5cffc4b8de57
comparison
equal deleted inserted replaced
1336:33d5c2471c09 1337:52a3f38cbfeb
1 function y = postpad(x,l,c) 1 function y = postpad (x, l, c)
2 2
3 # postpad(x,l) 3 # postpad (x, l)
4 #
4 # Appends zeros to the vector x until it is of length l. 5 # Appends zeros to the vector x until it is of length l.
5 # postpad(x,l,c) appends the constant c instead of zero. 6 # postpad (x, l, c) appends the constant c instead of zero.
6 # 7 #
7 # If length(x) > l, elements from the end of x are removed 8 # If length (x) > l, elements from the end of x are removed
8 # until a vector of length l is obtained. 9 # until a vector of length l is obtained.
9 10
10 # Author: 11 # Author:
11 # Tony Richardson 12 # Tony Richardson
12 # amr@mpl.ucsd.edu 13 # amr@mpl.ucsd.edu
13 # June 1994 14 # June 1994
14 15
15 if(nargin == 2) 16 if (nargin == 2)
16 c = 0; 17 c = 0;
17 elseif(nargin<2 || nargin>3) 18 elseif (nargin < 2 || nargin > 3)
18 usage ("postpad(x,l) or postpad(x,l,c)"); 19 usage ("postpad (x, l) or postpad (x, l, c)");
19 endif 20 endif
20 21
21 if(is_matrix(x)) 22 if (is_matrix (x))
22 error("first argument must be a vector"); 23 error ("first argument must be a vector");
23 elseif(!is_scalar(l)) 24 elseif (! is_scalar (l))
24 error("second argument must be a scaler"); 25 error ("second argument must be a scaler");
25 endif 26 endif
26 27
27 if(l<0) 28 if (l < 0)
28 error("second argument must be non-negative"); 29 error ("second argument must be non-negative");
29 endif 30 endif
30 31
31 lx = length(x); 32 lx = length (x);
32 33
33 if(lx >= l) 34 if (lx >= l)
34 y = x(1:l); 35 y = x(1:l);
35 else 36 else
36 if(rows(x)>1) 37 if (rows (x) > 1)
37 y = [ x; c*ones(l-lx,1) ]; 38 tmp = c * ones (l-lx, 1);
39 y = [x; tmp];
38 else 40 else
39 y = [ x c*ones(1,l-lx) ]; 41 tmp = c * ones (1, l-lx);
42 y = [x, tmp];
40 endif 43 endif
41 endif 44 endif
42 45
43 endfunction 46 endfunction