561
|
1 function y = postpad(x,l,c) |
904
|
2 |
|
3 # postpad(x,l) |
|
4 # Appends zeros to the vector x until it is of length l. |
|
5 # postpad(x,l,c) appends the constant c instead of zero. |
561
|
6 # |
904
|
7 # If length(x) > l, elements from the end of x are removed |
|
8 # until a vector of length l is obtained. |
561
|
9 |
|
10 # Author: |
|
11 # Tony Richardson |
|
12 # amr@mpl.ucsd.edu |
|
13 # June 1994 |
|
14 |
|
15 if(nargin == 2) |
|
16 c = 0; |
|
17 elseif(nargin<2 || nargin>3) |
904
|
18 usage ("postpad(x,l) or postpad(x,l,c)"); |
561
|
19 endif |
|
20 |
|
21 if(is_matrix(x)) |
|
22 error("first argument must be a vector"); |
|
23 elseif(!is_scalar(l)) |
|
24 error("second argument must be a scaler"); |
|
25 endif |
|
26 |
|
27 if(l<0) |
|
28 error("second argument must be non-negative"); |
|
29 endif |
|
30 |
|
31 lx = length(x); |
|
32 |
|
33 if(lx >= l) |
|
34 y = x(1:l); |
|
35 else |
|
36 if(rows(x)>1) |
|
37 y = [ x; c*ones(l-lx,1) ]; |
|
38 else |
|
39 y = [ x c*ones(1,l-lx) ]; |
|
40 endif |
|
41 endif |
|
42 |
|
43 endfunction |