Guest User

Untitled

a guest
May 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.72 KB | None | 0 0
  1. function teikna2
  2.  
  3.     global x y pt;
  4.    
  5.     f = figure;  
  6.    
  7.     aH=axes('Xlim', [0 1], 'Ylim', [0 1]);
  8.    
  9.     y=rand(15,1);
  10.     x=1:15;
  11.     h=plot(x,y, ...
  12.         'color','red',...
  13.         'lineWidth',3,...
  14.         'ButtonDownFcn',@startDragFcn);
  15.  
  16.     set(f,'WindowButtonUpFcn',@stopDragFcn);
  17.  
  18.     function startDragFcn(varargin)
  19.         set(f,'WindowButtonMotionFcn',@draggingFcn)
  20.     end
  21.  
  22.     function draggingFcn(varargin)
  23.         pt=get(aH,'CurrentPoint');
  24.         disp([num2str(pt(1)) '   ' num2str(pt(3))]);
  25.         y(abs(x-pt(1))==min(abs(x-pt(1))))=pt(3);
  26.         set(h,'YData',y);
  27.        
  28.     end
  29.  
  30.     function stopDragFcn(varargin)
  31.         set(f,'WindowButtonMotionFcn','');
  32.     end
  33. end
Add Comment
Please, Sign In to add comment