Reputation: 5960
I think I understand how to customize the existing data tip to the extent it is described in this Mathworks video. But what I want to do is display other related data values for the selected point on the figure.
For example, I can show the position (x,y,z), but I would like to show the time associated with the plot at that position.
In addition, I have several sets plotted on the same figure. Each call to the plot function returns a separate handle, so the individual plots are organized in a hierarchical data structure, keeping each entity separate.
I want the custom data tip to display values related to its data set, like an ID value for that set, for example.
Is there a way to determine the handle for the plot associated with the selected data point (that the data tip is referring to)?
UPDATE
I notice that there is a field in the plot called "UserData" that I can attach my data to. Is there a way, maybe, to reach this data from the Data Tip update function?
UPDATE 2
I can see that the datatip callback is passed a handle called "event_obj". This is a structure with a "Target" and "Position" field. The Position is just the x,y,z position on the figure. The Target is another structure where I can see my UserData structure is located. It also contains the arrays for the x,y and z values for every data point in that plot set. What I need now is the index for the datapoint referred to by the datatip. Then I think I can do the rest with my UserData.
Upvotes: 1
Views: 483
Reputation: 5960
The datatip callback function has two paramters: obj and event_obj.
As mentioned in the question, the event_obj structure contains the Target field, which is a structure that contains the user definable UserData. Any user data can be added to this structure, apparently. In my case, I added all of the arrays I might need that have values corresponding to each of the points plotted in the plot object being pointed to by the datatip cursor.
After examining the other parameter, obj, I see that is contains the Cursor object. One field in the Cursor structure is DataIndex. This is apparently the index into the arrays used to plot the X and Y values (and Z values if it's a 3D plot).
So, with this information, I am able to obtain any other corresponding value from the other vectors that I attached to the object with the original plot handle. That object is simply event_obj.Target.
Now I have fully elaborated datatips with any of the other corresponding values I might want to show for the plotted item referred to by the data tip.
Upvotes: 0