如何在matlab中使用鼠标移动楼梯图

时间:2012-10-13 17:36:53

标签: matlab

我需要使用鼠标指针移动图形的楼梯案例模型。更具体地说,如果我使用鼠标指针移动水平箭头标记中显示的水平图...那么相邻的图层也应移动相应的移动水平线...类似于垂直轴..我怎么能在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',[])

`

1 个答案:

答案 0 :(得分:0)

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

使用我提到的一些关键词进行一些研究,你最终会想到这一点。