changeset 11409:dd539a976451

signal/detrend.m: Also accept polynomial order as a string for compatibility
author Soren Hauberg <hauberg@gmail.com>
date Thu, 23 Dec 2010 15:57:40 +0100
parents 6154672afa9a
children 2df163be223e
files scripts/ChangeLog scripts/signal/detrend.m
diffstat 2 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Dec 17 21:41:53 2010 +0100
+++ b/scripts/ChangeLog	Thu Dec 23 15:57:40 2010 +0100
@@ -1,3 +1,7 @@
+2010-12-23  Soren Hauberg  <hauberg@gmail.com>
+	* signal/detrend.m: Also accept polynomial order as a string ("constant" or
+	"linear") for compatibility with Matlab.
+
 2010-12-22  Konstantinos Poulios  <logari81@gmail.com>
 
 	* plot/private/__axis_label__.m: Trigger fltk graphics redraw immediately
--- a/scripts/signal/detrend.m	Fri Dec 17 21:41:53 2010 +0100
+++ b/scripts/signal/detrend.m	Thu Dec 23 15:57:40 2010 +0100
@@ -27,22 +27,30 @@
 ##
 ## The second argument is optional.  If it is not specified, a value of 1
 ## is assumed.  This corresponds to removing a linear trend.
+##
+## The order of the polynomial can also be given as a string, in which case
+## @var{p} must be either @t{"constant"} (corresponds to @code{@var{p}=0}) or
+## @t{"linear"} (corresponds to @code{@var{p}=1}).
+## @seealso{polyfit}
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
 ## Created: 11 October 1994
 ## Adapted-By: jwe
 
-function y = detrend (x, p)
-
-  if (nargin == 1)
-    p = 1;
-  elseif (nargin == 2)
-    if (! (isscalar (p) && p == round (p) && p >= 0))
-      error ("detrend: p must be a nonnegative integer");
+function y = detrend (x, p = 1)
+  ## Check input
+  if (nargin > 0 && isreal (x) && ndims (x) <= 2)
+    ## Check p
+    if (ischar (p) && strcmpi (p, "constant"))
+      p = 0;
+    elseif (ischar (p) && strcmpi (p, "linear"))
+      p = 1;
+    elseif (!isscalar (p) || p < 0 || p != round (p))
+      error ("detrend: second input argument must be 'constant', 'linear' or a positive integer");
     endif
   else
-    print_usage ();
+    error ("detrend: first input argument must be a real vector or matrix");
   endif
 
   [m, n] = size (x);