diff 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
line wrap: on
line diff
--- a/scripts/general/postpad.m	Fri Aug 25 01:53:42 1995 +0000
+++ b/scripts/general/postpad.m	Fri Aug 25 02:16:01 1995 +0000
@@ -1,10 +1,11 @@
-function y = postpad(x,l,c)
+function y = postpad (x, l, c)
 
-# postpad(x,l)
+# postpad (x, l)
+#
 # Appends zeros to the vector x until it is of length l.
-# postpad(x,l,c) appends the constant c instead of zero.
+# postpad (x, l, c) appends the constant c instead of zero.
 #
-# If length(x) > l, elements from the end of x are removed
+# If length (x) > l, elements from the end of x are removed
 # until a vector of length l is obtained.
 
 # Author:
@@ -12,31 +13,33 @@
 #  amr@mpl.ucsd.edu
 #  June 1994
 
-  if(nargin == 2)
+  if (nargin == 2)
     c = 0;
-  elseif(nargin<2 || nargin>3)
-    usage ("postpad(x,l) or postpad(x,l,c)");
+  elseif (nargin < 2 || nargin > 3)
+    usage ("postpad (x, l) or postpad (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");
+  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");
+  if (l < 0)
+    error ("second argument must be non-negative");
   endif
 
-  lx = length(x);
+  lx = length (x);
 
-  if(lx >= l)
+  if (lx >= l)
     y = x(1:l);
   else
-    if(rows(x)>1)
-      y = [ x; c*ones(l-lx,1) ];
+    if (rows (x) > 1)
+      tmp = c * ones (l-lx, 1);
+      y = [x; tmp];
     else
-      y = [ x c*ones(1,l-lx) ];
+      tmp = c * ones (1, l-lx);
+      y = [x, tmp];
     endif
   endif