adding extra information in datacursormode text box

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.

 채택된 답변

Matt Fig
Matt Fig 2011년 3월 28일

0 개 추천

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.

추가 답변 (1개)

Tapi Iho
Tapi Iho 2011년 3월 29일

0 개 추천

Is there a way to set the datacursor update function to return the array index value instead of the x-value of that cell? This would work well.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2011년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by