2012-10-13 27 views
0

 如何在Matlab使用鼠标来移动一个楼梯情节

我需要移动用小鼠pointer.More具体地,如果我移动使用鼠标在水平箭头标记表示水平情节的曲线图的情况下,楼梯模型指针...然后相邻层也应该移动与相应的移动水平线...类似的垂直轴..我怎么能做到这一点在matlab中。好心帮助我..

下面写的代码完全移动的阴谋 但我需要移动确切的线(楼梯图的垂直/水平)而不会干扰其他线。好心帮我...

`

loglog(handles.axes1,a,b,'r') 
hold on 
% h=loglog(handles.axes1,x,y,'w') 
h=stairs(handles.axes1,x,y,'w') 
set(h,'ButtonDownFcn',@startmovit); 

gui = get(gcf,'UserData'); 
drawnow 
set(gcf,'windowbuttonmotionfcn','') 
set(gcf,'windowbuttonupfcn','') 

function startmovit(src,evnt) 


% Unpack gui object 
gui = get(gcf,'UserData'); 

% Remove mouse pointer 
set(gcf,'PointerShapeCData',nan(16,16)) 
set(gcf,'Pointer','custom'); 

% Set callbacks 
gui.currenthandle = src; 
thisfig = gcbf(); 
set(thisfig,'WindowButtonMotionFcn',@movit) 
set(thisfig,'WindowButtonUpFcn',@stopmovit); 

% Store starting point of the object 
gui.startpoint = get(gca,'CurrentPoint') 
set(gui.currenthandle,'UserData',{get(gui.currenthandle,'XData') get(gui.currenthandle,'YData')}); 

% Store gui object 
set(gcf,'UserData',gui); 

function movit(src,evnt) 
% Unpack gui object 
gui = get(gcf,'UserData'); 

try 
if isequal(gui.startpoint,[]) 
    return 
end 
catch 
end 

% Do "smart" positioning of the object, relative to starting point... 
pos = get(gca,'CurrentPoint')-gui.startpoint 
XYData = get(gui.currenthandle,'UserData') 

% set(gui.currenthandle,'XData',XYData{1} + pos(1,1)) 
% set(gui.currenthandle,'YData',XYData{2} + pos(1,2)) 

set(gui.currenthandle,'XData',XYData{1} + pos(1,1)) 
set(gui.currenthandle,'YData',XYData{2} + pos(1,2)) 


% dx=XYData 
% dy=XYData 
% 
% h=findobj(allchild(gca),'selected','on') 
% set(h,'Xdata',get(h,'Xdata')+dx,'Ydata',get(h,'Ydata')+dy) 

outData1 = get(gui.currenthandle,'XData')' 
outData2 = get(gui.currenthandle,'YData') 
% newea=outData1 
handles = guidata(gcf); 
drawnow; 
% Store gui object 
set(gcf,'UserData',gui); 


function stopmovit(src,evnt) 

% Clean up the evidence ... 

thisfig = gcbf(); 
gui = get(gcf,'UserData'); 
set(gcf,'Pointer','arrow'); 
set(thisfig,'WindowButtonUpFcn',''); 
set(thisfig,'WindowButtonMotionFcn',''); 
drawnow 
set(gui.currenthandle,'UserData','') 
set(gcf,'UserData',[]) 

`

回答

0

这个问题不容易解决。您需要利用Matlab的绘图处理系统,该系统用于管理图形窗口中的所有绘图元素。这个过程将涉及确定您的鼠标何时指向您的线路,以及当用户点击并拖动这些元素时要执行的操作。

使用我提到的一些关键字进行一些研究,你最终会弄清楚这一点。