From 2f31897ffd35221b0310b0c0089933f5ca13cfa0 Mon Sep 17 00:00:00 2001
From: Johannes Keyser <johannes.keyser@sport.uni-giessen.de>
Date: Tue, 22 Mar 2022 14:53:41 +0100
Subject: [PATCH] Put example into its own script file.

---
 TheilSen.m | 19 -------------------
 example.m  | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 19 deletions(-)
 create mode 100644 example.m

diff --git a/TheilSen.m b/TheilSen.m
index 13e5f81..0f464bd 100644
--- a/TheilSen.m
+++ b/TheilSen.m
@@ -12,25 +12,6 @@ function [m, b] = TheilSen(data)
 % b: Estimated offsets.
 %
 %
-% EXAMPLE
-% -------
-% n = 100;
-% outN = round(0.2 * n);
-% noise = randn(n, 2) * 0.1;
-% noise(randi(n * 2, [outN, 1])) = randn(outN, 1) * 5;
-% data = [linspace(0, 10, n)', linspace(0,5,n)'] + noise;
-% Bhat = [ones(n, 1), data(:, 1)] \ data(:, 2);
-% [m, b] = TheilSen(data);
-% plims = [min(data(:, 1)), max(data(:, 1))]';
-% figure()
-% plot(data(:, 1), data(:, 2), 'k.', ...
-%     plims, plims * m + b, '-r',...
-%     plims, plims * Bhat(2) + Bhat(1), '-b', 'linewidth', 2)
-% legend('Data', 'Theil-Sen', 'Least Squares', 'location', 'NW')
-% title(sprintf('Acual Slope = %2.3g, LS est. = %2.3g, TS est. = %2.3g', ...
-%       [0.5 Bhat(2) m]))
-%
-%
 % Source:
 %   Gilbert, Richard O. (1987), "6.5 Sen's Nonparametric Estimator of
 %   Slope", Statistical Methods for Environmental Pollution Monitoring,
diff --git a/example.m b/example.m
new file mode 100644
index 0000000..62a4d59
--- /dev/null
+++ b/example.m
@@ -0,0 +1,15 @@
+n = 100;
+outN = round(0.2 * n);
+noise = randn(n, 2) * 0.1;
+noise(randi(n * 2, [outN, 1])) = randn(outN, 1) * 5;
+data = [linspace(0, 10, n)', linspace(0,5,n)'] + noise;
+Bhat = [ones(n, 1), data(:, 1)] \ data(:, 2);
+[m, b] = TheilSen(data);
+plims = [min(data(:, 1)), max(data(:, 1))]';
+figure()
+plot(data(:, 1), data(:, 2), 'k.', ...
+     plims, plims * m + b, '-r', ...
+     plims, plims * Bhat(2) + Bhat(1), '-b', 'linewidth', 2)
+legend('Data', 'Theil-Sen', 'Least Squares', 'location', 'NW')
+title(sprintf('Acual Slope = %2.3g, LS est. = %2.3g, TS est. = %2.3g', ...
+      [0.5 Bhat(2) m]))
-- 
GitLab