Displaying extra information for datapoints on a plot

10 views (last 30 days)
Lets say I have two vectors x and y, which describe the position. When I plot them, I want to click on a data point and be able to see the t (time) value which I have created those vectors with. Is this possible, how would I do it?

Answers (1)

Walter Roberson
Walter Roberson on 26 May 2015
See datacursormode() and set an UpdateFcn on it. Return a cell array of strings representing the text to be displayed.
The event structure passed in will tell you your X and Y coordinates, but will not directly tell you which point you are examining. You can calculate Euclidean distances from your known points in order to figure out which graph point you are closest to, which gives you the index, you access your time array at the index, create suitable text, and Viola's Your Uncle.
Or you could instead cheat a little by drawing in 3D with the Z being your time coordinate, and telling view() that you want to look down from the top so that only the X and Y affect the drawing. Then you either say that it is Good Enough that the data cursor displays the time under the name 'Z', or else you write a simple UpdateFcn that grabs the X, Y, Z, and outputs text naming them as X, Y, and T.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!