1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
function demo
% Customize datatip string to display 'Amplitude' and
% 'Time'.
% The fonction display strings at positions specified in points,
% as those positions are curve points, the routine create a box(eps) and % display the string only in that box ( the center being one of the point given %in points) works also with subplot,etc....
global points;
global strng_datas;
global eps;
fig = figure;
z = peaks;
subplot(1,2,2)
plot(z(:,30:35))
subplot(1,2,1)
plot(z(:,31:36))
dcm_obj = datacursormode(fig);
points = [28.6148 0.78957];
strng_datas = cell(1,1)
strng_datas{1} = sprintf('mean : %0.6g \n std : %0.6g \n',28.6148,0.78957)
eps =[2 0.1];
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on','UpdateFcn',@myupdatefcn)
% mouse click on plot
function [txt] = myupdatefcn(obj,event_obj)
global points;
global strng_datas;
global eps;
% eps
% Display 'Time' and 'Amplitude'
pos = get(event_obj,'Position');
nbr_points = length(points(:,1));
for i = 1:nbr_points
if pos(1) > points(i,1) - eps(1) && pos(1) < points(i,1) + eps(1) && ...
pos(2) > points(i,2) - eps(2) && pos(2) < points(i,2) + eps(2)
txt = strng_datas{i};
else
% if pos(1) > points(1,1) - eps(1) && pos(2) < points(1,1) + eps(1)
% txt = strng_datas;
% end
txt = 'not found';
end
end
% txt = {['Time: ',num2str(pos(1))],['Amplitude: ',num2str(pos(2))]}; |
Partager