adding extra information in datacursormode text box
2 views (last 30 days)
Show older comments
Hello,
I have a subplot with hundreds of (x,y)-points displayed and I want to be able to click at a point and see some textual identification information besides the x and y values. Each point has a unique information.
The straight forward way would be to store the information in an array of same size as the data array, but what is the easiest way to access this array with the datacursormode? The datacursormode returns the x and y values of each point, but it is a little bit inconvient to use those for looking up the identification text for each point, because some points may have same values in different subplots etc.
0 Comments
Accepted Answer
Matt Fig
on 28 Mar 2011
If you right click on the data cursor text, you can choose: Edit Text Update Function.
In the function, put whatever you want.
EDIT
There are probably many ways to do what you are asking. Here is what I did, as an example.
L = plot(rand(1,4),rand(1,4),'*','markersize',8);
axis([0 1 0 1])
set(L,'userdata',{'First','Second','Third','Fourth'}) % The extra info.
Now I select the datacursor and set the text update function to this:
function output_txt = myfunction(obj,event_obj)
pos = get(event_obj,'Position');
D = get(event_obj.Target,'Userdata'); % Get the extra information.
xd = get(event_obj.Target,'Xdata');
I = find(xd==event_obj.Position(1),1);
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)],...
D{I}}; % Place extra information at end of string.
More Answers (1)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!