0

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

`

4

1 回答 1

0

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

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

于 2012-10-14T00:34:56.940 回答