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?

1 次查看(过去 30 天)
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?

采纳的回答

Matthew Eicholtz
Matthew Eicholtz 2017-5-3
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?
  4 个评论
Matthew Eicholtz
Matthew Eicholtz 2017-5-5
Copy and paste the entirety of my code into a new file, save, and run it. It should not give any error. Once you see how the buttons work, you can insert them in your code appropriately.
Matthew Eicholtz
Matthew Eicholtz 2017-5-5
I think you received that error because you copied the middle part of the code (that includes an "end" statement), but not the function header. Is that correct?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by