function mousedrag
global current_selected xy_start xdata_start ydata_start
h=plot(1,1,’*’);
set(h,‘ButtonDownFcn’,@select);
set(gcf,‘WindowButtonUpFcn’,@change_state,‘WindowButtonMotionFcn’,@move)
end
function select(obj,event)
global current_selected xy_start xdata_start ydata_start
set(obj,‘Selected’,‘on’);
current_selected=obj;
xy_start=get(gca,‘CurrentPoint’);
xdata_start=get(obj,‘xdata’);
ydata_start=get(obj,‘ydata’);
end
function change_state(obj,event)
global current_selected
set(current_selected,‘Selected’,‘off’);
current_selected=0;
end
function move(obj,event)
global current_selected xy_start xdata_start ydata_start
if current_selected~=0
xy_current=get(gca,‘CurrentPoint’);
dx=xy_current(1)-xy_start(1);
dy=xy_current(3)-xy_start(3);
set(current_selected,‘xdata’,xdata_start+dx,‘ydata’,ydata_start+dy);
end
end