简体   繁体   中英

How to move a staircase plot using mouse in matlab

I need to move the stair case model of the graph using mouse pointer.More specifically, if i move the horizontal plot showing in horizontal arrow marks using the mouse pointer...then the adjacent layers also should move withe the corresponding moving horizontal line... similarly for the vertical axis.. How can i do this in matlab. kindly help me..

The code written below moves the plot entirely but i need to move the exact line (vertical / horizontal of staircase plot) without disturbing other lines. kindly help me...

`

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',[])

`

This problem is not solved easily. You need to take advantage of Matlab's plot handle system which is what is used for managing all the plot elements in a figure window. The process is going to involve determining when your mouse is pointing to your line and what to do when the user clicks and drags over these elements.

Do some research using some of the keywords I mentioned and you will eventually figure this out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM