From 2b85b128c6839374c887161250bb5962b78d0dc5 Mon Sep 17 00:00:00 2001
From: Johannes Keyser <johannes.keyser@sport.uni-giessen.de>
Date: Wed, 23 Mar 2022 19:39:56 +0100
Subject: [PATCH] Replace nanmedian(X) by median(X, 'omitnan').

- This ends the dependency on the Statistics
  and Machine Learning Toolbox.
---
 TheilSen.m | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/TheilSen.m b/TheilSen.m
index bfa7fda..5f8dd49 100644
--- a/TheilSen.m
+++ b/TheilSen.m
@@ -51,11 +51,11 @@ if Num_Dim == 2  % normal 2D case
                       (data(i, 1) - data(i:end, 1));
     end
 
-    b1 = nanmedian(C(:));  % calculate slope estimate
+    b1 = median(C(:), 'omitnan');  % calculate slope estimate
     
     if nargout == 2
         % calculate intercept if requested
-        b0 = nanmedian(data(:, 2) - b1 * data(:, 1));
+        b0 = median(data(:, 2) - b1 * data(:, 1), 'omitnan');
     end
     
 else
@@ -69,11 +69,14 @@ else
 
     % stack layers of C to 2D
     Cprm = reshape( permute(C, [1, 3, 2]), [], size(C, 2), 1 );
-    b1 = nanmedian(Cprm, 1);	 % calculate slope estimate
+    b1 = median(Cprm, 1, 'omitnan');  % calculate slope estimate
     
     if nargout == 2
         % calculate all intercepts if requested
         b0 = nanmedian( bsxfun(@minus, data(:, end), ...
-                        bsxfun(@times, b1, data(:, 1:end-1))) );
+                        bsxfun(@times, b1, data(:, 1:end-1))), ...
+                        'omitnan');
     end
+end
+
 end
\ No newline at end of file
-- 
GitLab