From 60ebf52de4131374a1d6038655df513bbd8b9be7 Mon Sep 17 00:00:00 2001
From: Thomas West <tw00956@surrey.ac.uk>
Date: Tue, 3 Sep 2024 15:23:24 +0000
Subject: [PATCH] Cursor function when studying .mat figures.

---
 Function/myupdatefcn.m | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Function/myupdatefcn.m

diff --git a/Function/myupdatefcn.m b/Function/myupdatefcn.m
new file mode 100644
index 0000000..9ab0a9e
--- /dev/null
+++ b/Function/myupdatefcn.m
@@ -0,0 +1,15 @@
+function txt = myupdatefcn(~, event_obj, positions, velocities)
+    % Customizes text of data tips
+    pos = get(event_obj,'Position');  % Get the position of the data tip
+    idx = find(ismember(positions, pos, 'rows'));  % Find the index of the position in the matrix
+
+    if isempty(idx)
+        txt = {'Position:', pos, 'Velocity: Not found'};
+    else
+        vel = velocities(idx, :);  % Extract corresponding velocity
+        vel_mag = norm(vel);  % Calculate the magnitude of the velocity vector
+        txt = {['Position: (', num2str(pos(1)), ', ', num2str(pos(2)), ', ', num2str(pos(3)), ')'], ...
+               ['Velocity: (', num2str(vel(1)), ', ', num2str(vel(2)), ', ', num2str(vel(3)), ')'], ...
+               ['Velocity Magnitude: ', num2str(vel_mag), ' m/s']};  % Add magnitude to the data tip
+    end
+end
\ No newline at end of file
-- 
GitLab