changeset 957:2412f407749a

Add function for drawing arrow on plot
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 12 Dec 2018 23:16:44 +0100
parents d6ede7f5cbf9
children a4ad90b37998 e54c2f54dbfe ea8fefc326b2
files arrowAnnotation.m
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arrowAnnotation.m	Wed Dec 12 23:16:44 2018 +0100
@@ -0,0 +1,23 @@
+% Draw an arrow from p1 to p2, with text attached
+function [h] = arrowAnnotation(p1,p2)
+    ah = gca;
+    xl = ah.XLim(1);
+    xr = ah.XLim(2);
+
+    yl = ah.YLim(1);
+    yr = ah.YLim(2);
+
+    dx = xr - xl;
+    dy = yr - yl;
+
+    s = [
+        ah.Position(1) + (p1(1) - xl)/dx*ah.Position(3),
+        ah.Position(1) + (p2(1) - xl)/dx*ah.Position(3),
+    ];
+    t = [
+        ah.Position(2) + (p1(2) - yl)/dy*ah.Position(4),
+        ah.Position(2) + (p2(2) - yl)/dy*ah.Position(4),
+    ];
+
+    h = annotation('arrow', s, t);
+end