THERE IS THE SOLUTION BELOW!
This (x,y) value actually corresponds to a t value, which I want to see on the plot. What can I do?
Clearly matlab has the ability to display multiple information in the datapoint box:
just call it as "TimePlot(x,y,t)" and it will work. This code, I believe, also illustrates a few key points in modifying datatips.
function TimePlot( varargin )
x=varargin{1};
y=varargin{2};
t=varargin{nargin};
fh=figure;
plot(varargin{1:nargin-1})
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');
ind=intersect(Find(x,pos(1),1e-10),Find(y,pos(2),1e-10));
if(length(ind)~=1)
text='err';
else
text=num2str(t(ind),4);
end
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)],['T: ',text]};
% 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
end
dcm=datacursormode(fh);
datacursormode on
set(dcm,'updatefcn',@myfunction)
end
function [ out ] = Find( vector, value ,precision)
if nargin < 3
precision = 0.0001;
end
out=[];
for i=1:length(vector)
if(abs(vector(i)-value)<precision)
out=[out i];
end
end
end