MATLAB: I have a gui and i want to have 4 buttons to pan the graph so one that goes left right up and down, how would i do this

guiMATLABnuttonspanpush buttons

I have a gui and i want to have 4 buttons to pan my graph so one that goes left right up and down, how would i do this?

Best Answer

The easy answer: I would suggest using the built-in pan tool in the figure toolbar.
The slightly more complicated answer: Try adapting the following code to your GUI. Here, I am creating a plot of some random numbers and using 4 uicontrols for pan buttons.
function panfigure()
% Setup figure
figure;
plot(rand(10,1),rand(10,1));
ax = gca;
set(ax,...
'Units','pixels',...
'Position',[140 100 400 300],...
'XLimMode','manual',...
'YLimMode','manual');
% Create pushbuttons for panning
uicontrol('Style','pushbutton','Position',[20 40 40 20],'String','Left','Callback',{@panleft,ax});
uicontrol('Style','pushbutton','Position',[100 40 40 20],'String','Right','Callback',{@panright,ax});
uicontrol('Style','pushbutton','Position',[60 60 40 20],'String','Up','Callback',{@panup,ax});
uicontrol('Style','pushbutton','Position',[60 20 40 20],'String','Down','Callback',{@pandown,ax});
end
% Callback functions
function panleft(obj,evt,ax)
dx = diff(ax.XLim);
ax.XLim = ax.XLim-0.05*dx;
end
function panright(obj,evt,ax)
dx = diff(ax.XLim);
ax.XLim = ax.XLim+0.05*dx;
end
function panup(obj,evt,ax)
dy = diff(ax.YLim);
ax.YLim = ax.YLim-0.05*dy;
end
function pandown(obj,evt,ax)
dy = diff(ax.YLim);
ax.YLim = ax.YLim+0.05*dy;
end
Does that help?