display extra value in datacursor

3 views (last 30 days)
Joanie
Joanie on 11 Jun 2014
Answered: Zikobrelli on 12 Jun 2014
Is there a way to add other values to the datacursor? So besides x and y.
I have an array with x and y values and a value d. Now I like to see value d of the selected point in the datacursor.

Answers (1)

Zikobrelli
Zikobrelli on 12 Jun 2014
Data cursor has a callback function that can be found like this: on your plot: 1)click on the data cursor 2)Right click on the plot 3)Edit text Update function
You should get smthg like this: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ù function output_txt = myfunction(obj,event_obj) % Display the position of the data cursor % obj Currently not used (empty) % event_obj Handle to event object % output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position'); output_txt = {['X: ',num2str(pos(1),4)],... ['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well if length(pos) > 2 output_txt{end+1} = ['Z: ',num2str(pos(3),4)]; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4)you can add more info/values and then save function to workspace
Cheers,

Tags

Community Treasure Hunt

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

Start Hunting!